I want to separate some functions into a file named helpers.js, in which I have put the below shown code. What should I do to access the app variable from inside my method in order to be able to fetch my config element named Path?
Helpers = {
fs: require('fs'),
loadFileAsString: function(file) {
return this.fs.readFileSync( app.set('Path') + file)+ '';
}
}
module.exports = Helpers;
So from what I see you need the
appvariable form Express. You can send it as a function param to loadFileAsString, for ex:helpers.js
some_file.js
If you want the app to be global though you can do that also:
global.app = appand you can access app everywhere without sending it as a function param.