I read the answers to How do I return the response from an asynchronous call?. I am still a little confused why this piece of code isn't working correctly. bool is returning "Promise {pending}", which it should not, since I've put the await keyword there.
db.js:
async function validateUser(username, password) {
var sql = "SELECT * FROM users WHERE username = ? AND password = ?";
var values = [username, password];
let promise = new Promise((resolve, reject) => {
con.query(sql,values, function(err, results) {
if (err) throw err;
if (results.length > 0){
console.log('true');
resolve("true");
}
else{
console.log('false');
reject("false");
}
})
});
let bool = await promise; // wait until the promise resolves (*)
return bool;
}