I’m a Nodes.js noob and I’m trying to get my head around module constructs. Thus far I have a module (testMod.js) defined this class construct:
var testModule = {
input : "",
testFunc : function() {
return "You said: " + input;
}
}
exports.test = testModule;
I attempt to call the testFunc() method thusly:
var test = require("testMod");
test.input = "Hello World";
console.log(test.testFunc);
But I get a TypeError:
TypeError: Object #<Object> has no method 'test'
What the frick am I doing wrong?
It’s a namespacing issue. Right now:
You could do:
Or, instead of
exports.testyou could domodule.exports = testModule, then: