NodeJS Module

December 11, 2012 ยท View on GitHub

The NodeJS sm module is installed via npm:

npm install -g sm

It can be used to

Resolve dependencies dynamically

require("sm").for("<packageRoot>").resolve("<alias>/<moduleId>").then(function(path) {
	// Use `path`.
}, function(err) {
	// Error while making dependency available.
});

require("sm").for("<packageRoot>").require("<alias>/<moduleId>").then(function(api) {
	// Use `api`.
}, function(err) {
	// Error while making dependency available.
});

This will resolve, dowload and install the dependency referenced via <alias>/<moduleId> as long as:

  • The Package Descriptor at <packageRoot>/package.json allows for this dynamic install by declaring the <alias> in optionalMappings.