I have created a module like the following:
module.exports = function() {
function func1 () {
}
function func2 () {
}
return function() {
func1();
func2();
return value;
};
}
when I call the module in another file
myModule = require('myModule')
use the module
myModule()
I get an undefined value. what do I wrong?
You're exporting a function that when called returns another function which in turn will throw an
ReferenceError
saying thatvalue
is undefined which you can alleviate by definingvalue
.In order to run it you need to call it twice.
My guess is that you just want the value returned so wrap it in an IIFE