I have this code in Node.JS:
var mysql= require('mysql');
function first(){
var connection = mysql.createConnection({
host : 'xxxxx',
user : 'admin',
password : 'xxxxx',
database : 'xxxxx',
port : 'xxxxx'
});
connection.connect();
connection.query('select*from test', function (error, results, fields) {
if (error) throw error;
return results[0].num;
});
}
function two(){
res = first();
console.log(res);
}
two();
I need get the response but, in the console show Undefinied. How can I fix that?