r42
Mix in node's require, some angular dependency injection look&feel and the ease of use of RequireJS and what do you get?
Dependency injection done right for Node.js!
WARNING
This library is a work in progress. It won't have anything stable before 0.1.0. Please use with care. Right now, even small version changes can (and probably will) break your code.
Getting started
Installation
npm install r42
Your first module
Let's code lib/toto.js :
define(function (path, fs, _, dep1, dep2) {
return ;
});
Configuring & lauching your project
var r42 = require('r42');
var path = require('path');
r42.config({
baseDir: path.join(__dirname, 'lib'),
paths: {
_: 'lodash',
library: '../vendor/library',
sub: '../sub'
},
});
r42.inject(function (toto) {
});
More complex dependencies (in subfolders for example)
If you want to resolve complex names in subdirectories, you can use the optional
"replacer" argument of the define function. Here is an example:
define({
test: 'sub/folder/test',
}, function (test) {
});
The object maps an argument's name to the real module name locally. The argument name
will be replaced by the given module name before injection happens.