I've been using node.js for about a year, and I always did that kind of stuff. But for some reason (maybe it's related to 0.8.x) now when I do it, it doesn't work anymore.
Here's some code:
Let's say I have test.js
:
var test = {
datFunction: function(){ return 'oh yeah'; }
}
module.exports = test;
and I have test2.js
:
var test = require('./test');
// should output:
// { datFunction: [function] }
console.log(test);
// but outputs:
// {}
As I commented up there, it usually log'd the object with everything that was in there, but now it only gives me {}
.
Any idea why?
Thanks
You need to export test
in test.js
module.exports = test;
I have no idea about node.js but it seems you have a redeclaration of var test
.