NodeJS modules should export object constructors
Note I didn’t say always should export objects, but for the sanity of everyone involved, in many cases a required module should return a constructor and not a fully instantiated object. Today’s post is about why your NodeJS modules should look like this: /** * @constructor */ function myConstructor(someDependency) { /* setup my object here */ } module.exports = myConstructor; and not this: var myObj = { myService: new MyService() }; myObj.myFunction = function(foo) { /* do stuff with foo here */ }; module.exports = myObj; ...