First you will have to create a static method to be able to access it without creating an instance of Backend using static.
Now to use await you will need to use files. You could use the modifier async in its method to transform the return of getUsers in a resolution of a file, but as the value to be returned is inside a callback (onReceive), there is no way you can return the value with the declaration return. You will have to resort to creating an object Promise so you can use the callbacks resolve or reject inside the callback of database.on.
class Backend {
static getUsers() {
return new Promise((resolve, reject) => {
const database = firebase.database().ref('users/')
database.on('child_added', data => resolve({ data }))
})
}
}
async function imprimirUsers() {
const data = await Backend.getUsers()
console.log(data)
}
imprimirUsers()
You would like to load all users at once or get "listening" to each user entered?
– Erick M. Sprengel