I'm trying to grab the results of an SQL query in order to use it elsewhere in my code, but I just can't figure out how to get them out. I have nested functions so I tried to get it out through two calls of return, but what comes out isn't valid.
var users = getUsers();
function getUsers(req, res){
dbConnect(req,res);
return connection.query('SELECT * FROM USERS', function selectAll(err, rows, fields) {
if (err) {
throw err;
}
for (var i in rows) {
console.log(rows[i]);
}
return rows;
dbClose(req,res);
})
}
What's wrong here?