Saturday, November 3, 2018

javascript - returning data in node js

I have two files in my application,
DesignFactory.js:



var fs = require('fs');

var dotenv = require('dotenv');
dotenv.load();
var designtokenfile = require ('./designtokenfile');
var designtokendb = require ('./designtokendb');
var TYPE=process.env.TYPE;
var DesignFactory={};
DesignFactory.storeDesign = function(TYPE) {
if (TYPE == 'file') {
var data=design.designtokenfile.load();
console.log(data);


} else if (TYPE == 'db') {
return designtokendb;
}
};

module.exports.design=DesignFactory;


now, I have another designtokenfile.js file,

designtokenfile.js:



var fs = require('fs');
var load = function() {
fs.readFile('output.txt', 'utf8', function (err,data) {

return data;
if (err) {
return console.log(err);
}

});

};

module.exports.load=load;


So my problem is am not able get data returned from load method. when I print data inside storeDesign method returned from load function, it displays undefined.
but I want contents of output.txt inside storeDesign method.
Please help me.

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...