node package manager


Abstraction layer of require().

cloader (NodeJS)

Abstraction layer of require().

npm install cloader

Create a loader.js in your project root and instantiate a ComponentLoader:

// Creates a ComponentLoader instance
// Attaches it to GLOBAL.load

The next step is to add your libraries and virtual packages. They're relative to your project root.

// Libraries

// Virtual Packages
load.addPackage('auth-api', 'packages/auth_api/index.js');

The loader is defined inside a global variable, this means that you only have to require it inside your entry script.

// app.js

Because it's in a separate loader.js file, this is also possible:

// mocha

Pretty random example but this is merely an illustration.

// Packages, both virtual and real
var AuthApi			= load.p( 'auth-api' ),
	mongoose		= load.p( 'mongoose' ),
	crypto			= load.p( 'crypto' );

// Modules
var	UserModel		= load.m( 'Models/UserSystem/User' ),
	Cookie			= load.m( 'Models/UserSystem/Cookie' ),
	formSanitizer	= load.m( 'Tools/FormSanitizer' );

// Your specific module code (or unit-test)

You still load modules using their directory path, but those paths now behave like absolute paths and they are more easily readable and comprehensible.

You can also merge or separate your libraries and turn your virtual packages into real packages without having to change individual modules.

Go to the wiki for more in-depth documentation and configuration options.