This piece of code always returns undefined to the calling function. I'm new to JavaScript and I did try and look into some of the callback solutions on Stack Overflow and other resources but none of them worked for me. Any help with this would be highly appreciated. Thank you!
var funcs = require('./index.js');
var connected = require('./database')
query='SELECT * from trades'
const res = execute_rows(query)
console.log(res)
function execute_rows(query){
con = connected();
con.query(query, function(err, result, fields) {
if (err) {
return console.log(err);
}
console.log(result) //Displays correct results
return result; // Returns undefined to calling function
})
con.end();
}