I'm trying to make the following nodejs module:
exports.method = function () {
var init = true;
return function (args) {
console.dir(args);
};
};
But when I invoke this method I don't get console message:
require('./module.js').method({test: 1});
It returns a function instead of invoking it.
You need to execute the outer function, otherwise you're simply assigning it to exports.method.
In other words:
exports.method = function () {
var init = true;
return function (args) {
console.dir(args);
};
}();
Note the trailing ()