I have this function to connect to my DB and consult something in it.
function conn (text){
var mysql = require("mysql");
var connection = mysql.createConnection({
connectionLimit : 100, //important
host : 'xxx.xxx.xxx.xxx',
user : 'xxxxxx',
password : 'xxxxxxx',
database : 'xxxxxxxx'
});
connection.connect();
var queryString = 'SELECT usuario.idUsuario FROM usuario WHERE usuario.nickname = ' + '"' + text + '"';
function getID(text, callback){
connection.query(queryString, function(err, rows, fields) {
var id;
if (err){
callback(err, null);
}else{
for (var i in rows) {
id = rows[i].idUsuario;
}
callback(null, id);
}
});
}
var result;
getID(text, function(err, content) {
if (err) {
console.log(err);
} else {
result = content;
}
});
connection.end();
};
Now, i need to get the result in other variable to use it in other functions inside my JS file. How can i get that value without get code inside the variable?