Monday, 29 May 2017

how to return array in Node.js from module

getting undefined all the time "main.js":

var dbAccess = require('../dao/dbAccess');
dbaInstance = new dbAccess();
var wordPool = dbaInstance.getWordPool();
console.log (wordPool);

and "dbAccess.js" contains:

var DatabaseAccess = function() {}

DatabaseAccess.prototype.getWordPool = function () {
    RoundWord.find({},'words decoys', function(err, wordPoolFromDB) {
        if (err) throw err;
        //console.log(wordPoolFromDB); -working ok
        return (wordPoolFromDB);
    });
}

module.exports = DatabaseAccess;

why is it not working?



via V.Pud

No comments:

Post a Comment