I created a module like this:
module.exports = function foo(){
this.run = function ()
{
console.log("run");
}
}
now i want to require the module in an node.js application and immediatly get an instance. I tried to get it in a simple line, but it doesn't work. The code looks like this:
var foo = new require('./foo.js')();
foo.run();
foo will be undefined and therefore run cannot be raised.
First working Solution:
var foo = require('./foo.js');
var instance = new foo();
instance.run();
console.log('Hello world');
Second working Solution (as i understand adeneo)
function foo() {
this.run = function () {
console.log("run");
}
}
module.exports = new foo();
Which solution is more common ? are there more?