I use Nodejs to make SQL queries, and I'd like to save the result in a global variable, in order to use it in the rest of the file, I tried to use express and the global.storage, but no result yet, the console shows me undefined, my code is so below : and the result that is shown in the console is null.
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "espace_membre"
});
var pseudo1 = "amine";
var socketid = '3485858585';
var peerId = '4444';
var sqlResult = null ; // stockera une sortie SQL
con.connect(function(err) {
con.query("SELECT gender FROM gender WHERE socketid = '" + peerId + "'", function (err, result) {
console.log(result);
// affect la sortie à la variable global
sqlResult = result;
});
});
console.log( sqlResult );