Thursday, 27 April 2017

Return Variable in Node Module Call Back

I'm using this NPM package to get the CSV output of table from an access database.

I have my function structured as follows:

function createDB(mdbfile){
  var rawDB = mdb(mdbfile);
  var db = {}
  rawDB.tables(function(err, table){
    table.forEach(function(item){
      var rawTable = null;
      rawDB.toCSV(item, function(err, csv){
        rawTable = csv; //Doesn't work
      });
      console.log(rawTable); //Always null :(
      
      var newTable = Do stuff with CSV;
      db.item = newTable;
    });
  });

  return db
}

I'm sure this is some scoping issue but I'm new to node and don't know how to search for this properly. From what I can tell the module is synchronous but the scope doesn't work.

Any help would be appreciated! Unfortunately a client I have MUST use access DB file and I'm just trying to make this work.



via Segfaulter

No comments:

Post a Comment