0

When I do console.log(users) it gives me the desired output (array of objects) but with a Promise around it like this:

Promise {
  [
     {user1, ....},
     {user2, ....},
     {user3, ....},
  ]
}

How do I make this Promise go away? Check code down below.

Thanks in advance from a newbie.

async function getUsers(query){

    try{
        const results = await client.query(query);
        const data = results.rows;
        console.log("data",data)
        return  data;

    } catch(err) {
        console.log(err.stack);
    }finally{
        client.end();
    }
}

const users = getUsers(`Select * from users;`);

1 Answers1

0

Either add this line to a async function

const users = await getUsers(`Select * from users;`);

Or do it the pre node 10 route and use .then

getUsers().then(users => {
  console.log(users)
})

cWerning
  • 583
  • 1
  • 5
  • 15