I am working on creating a user login system and need to query the database. I am new to coding and I am struggling to understand callbacks and how data can be passed once the callback has happened. 

I have a MySQL query that gets called via a callback. The result of this, I then need to use in the following async function body for use in app.js as a promise. The async function sits inside a route file.

I tried creating a variable outside the callback scope as you can see here with users being declared before the `.query()` but I still receive `undefined` after it has run. I've also tried using the keyword `await` before connection.query so the function doesn't run until the callback is completed but that does not seem to work either.

Any help would be greatly appreciated at the minute as I'm still trying to understand how JS works. Thanks

```
async function getAll() {
var users;
var query = "SELECT * FROM `users`"; // query database to get 
    all the players

   // execute query
   connection.query(query, (err, result) => {
      if (err) {
        res.redirect('error.ejs');
        console.log(error.message);
      }

      users = result;

   });
return users.map(u => {
        const { password, ...userWithoutPassword } = u;
        return userWithoutPassword;
        });

```

}

The following function is where the async function is then called in app.js: 

```
function getAll(req, res, next) {
    userService.getAll().then(users => {
      console.log(users);
      res.json(users)}).catch(err => next(err)); 
}

```