When I am trying to get an array through this function:
function getdata() {
var messages=[];
var query=connection.query('SELECT * FROM chat', function(err,rows,fields) {
messages=rows;
});
return messages;
}
console.log(getdata()); // I get []
But anytime the result is [] but if I insert a console.log(rows) in the function, I have all my data.
So how can I do for the function to wait getting the data before returning messages?
EDIT,: I resolved the problem using async function