When designing an app, we usually ensures that our components are loosely coupled. In static typed language, we usually use an IoC container, to maintain our component registration and to resolve dependencies. There are Autofac, Ninject, Windsor, and many other in .NET world.

Designing a loosely coupled application in dynamic typed language is arguably easier, since we usually can inject any property to an object.

Currently , when developing a Node.js app, I prefer to use dedicated files to store dependencies.

As an example, I have registry.js to store common services.


exports.services = {
    commonUtils :require('./commonUtils.js'),
    config : require('./config.js')(),
    dbUtils : require('./dbUtils.js'),
    filters : require('./filters.js'),
    modelBinder : require('./modelBinder.js'),
    typeConverter : require('./typeConverter.js'),
    htmlHelpers : require('./htmlHelpers.js')

And in my consumer class, I reference that registry file

var coreServices =  require('../core/registry.js').services;

var modelBinder = coreServices.modelBinder,
    typeConverter = coreServices.typeConverter,
    filters = coreServices.filters;

This way, we only need to change the registry files if we want to use different implementation.