I'm having trouble retrieving a value using the mssql library
I have tried to put a variable in global scope and update the value using the recordset, put everything inside a function passing the value of the recordset as a return and use functions of setImmediate and setTimeout, but still trying to display the value in the console of date, is returned "undefined"
var express = require('express');
var sql = require("mssql");
var app = express();
var data;
getData();
function getData() {
var config = {
user: '', //usuário
password: '', //senha
server: '', //servidor
database: '' //db
};
sql.connect(config, function (err) {
if (err) console.log(err);
var request = new sql.Request();
request.query('SELECT ..........', function (err, array) {
if (err) console.log(err)
data = array.recordset;
sql.close();
});
});
}
var server = app.listen(8080, function () {
console.log('Server is running..\n' + data);
});