Reputation: 63647
Problem: I just started out in node.js and when using REPL to require
a module, its function keeps showing undefined. Where did it go wrong?
Also, why does the var s = require('./simple');
line result in an undefined
response? I am using node v0.6.2
simple.js
var counts = 0;
exports.next = function() { counts++; }
What I did in REPL
> var s = require('./simple');
undefined
> s.next
[Function]
> s.next()
undefined
> s.next();
undefined
Upvotes: 1
Views: 466
Reputation: 30430
That is completely normal, since your function doesn't actually return anything it would return undefined by default. Try this exports.next = function() {return counts++; }
you get the number before the addition.
Upvotes: 3