I was trying to add two module.exports
in my NodeJS module. I tried below code for my module:
exports.one = function(data){
const one = data;
};
module.exports = function(msg) {
console.log(one+'::'+msg);
};
And below code for index.js:
var myModule = require('./mymodule.js');
myModule.one('hi');
myModule('bro');
myModule('Dear');
myModule('Dude');
I was expected that it will log below data into the console:
hi bro
hi Dear
hi Dude
But the console says:
TypeError: myModule.one is not a function
at Object.<anonymous> (....
Please how do I solve this issue? There are Stack Overflow questions asking how to use multiple module.exports in NodeJS modules. But the answer is something like below:
exports.one = function (){};
exports.two = function (){};
But if I use that code, I have to use
myModule.one('hi');
myModule.two('bro');
myModule.two('Dear');
myModule.two('Dude');
Instead of:
myModule.one('hi');
myModule('bro');
myModule('Dear');
myModule('Dude');