You do not need to pass the http object because you can request it again in other modules. Node.js will return the same object from the cache.
If you need to pass an instance of an object to a module, one of the dangerous ways is to define it as global (without the var keyword). It will be visible in other modules.
A safer alternative is to define a module like this
// somelib.js module.exports = function( arg ) { return { myfunc: function() { console.log(arg); } } };
And import it like this:
var arg = 'Hello' var somelib = require('./somelib')( arg ); somelib.myfunc()
source share