Tuesday, 4 April 2017

(Javascript Node.js) How to get varibles from a IIFE

Please see my code below: I am trying to assign the recordset to a variable, can use index.js to call this variable out.

I am able to console.log the recordset. But when I call this IIFE, it is always says undefined.

var mssql = require('mssql');
var dbcon = require('./dbcon');

var storage = (function () {

  var connection = new mssql.Connection(dbcon);
  var request = new mssql.Request(connection);
  connection.connect(function (recordset) {
    request.query('select getdate()', function (err, recordset) {
      console.dir(recordset);
    });
    connection.close();
  });

})();

module.exports = storage;



via Chongran Hao

No comments:

Post a Comment