1

I want to use async await because I find it much more convenient than then method. But when I do I get this error:

const onceGetUsers = async () => await db.ref("users").once("value");
let users = await db.onceGetUsers(); // Syntax error: await is a reserved word
console.log(users);

Thx

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • You have to put it inside an `async function`. You can't just use it anywhere. – Bergi Nov 19 '17 at 17:54
  • Btw, the `await` in `onceGetUsers` is [pretty useless](https://stackoverflow.com/q/43353087/1048572) – Bergi Nov 19 '17 at 17:56

1 Answers1

2

It looks like you're not using await correctly. await can only be used inside a function declared async. In your code, you're using await outside (unless there's more to your code that you're not showing).

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441