exports are a reasonable way of expressing module dependencies and interfaces, and the tools for managing modular code are getting better all the time.
Much less of a consensus has developed around the best way to deliver CommonJS modules to a web browser, where the synchronous semantics of
require pose a non-trivial implementation challenge. This module loader contributes to that confusion, yet also demonstrates that an amply-featured module loader need not stretch into the hundreds or thousands of lines.
npm install install
cd path/to/node_modules git clone git://github.com/benjamn/install.git cd install npm install .
The first step is to create an
install function by calling the
makeInstaller method. Note that all of the options described below are
var install =;
The second step is to install some modules by passing a nested tree of
objects and functions to the
var require =;
Note that the
install function merely installs modules without
evaluating them, so the third and final step is to
require any entry
point modules that you wish to evaluate:
console;// => "/main.js"
This is the "root"
require function returned by the
function. If you're using the
install package in a CommonJS environment
like Node, be careful that you don't overwrite the
provided by that system.
Many more examples of how to use the
install package can be found in the