my problem is that I need to wait a bit before returning the value.
the function is returning the variable x before the var updates (or at least I think that it’s the problem).
var x; //now it's undefined
con.connect(function(err) {
if (err) throw err;
con.query("SELECT * FROM usrs", function (err, result) {
if (err) throw err;
x= result; //trying to update x
});
});
return x; //returns undefined(because it doesn't have enough time to change so it stays like it was at the beginning)