There are many ways to add features in Noder.io.
- Monkey patching like
noder.myFeature = myFeature
- Dependency injection
- Plugin
Noder.io provides a plugins system to make a package works easily as a plugin for Noder.io and also as a standalone module or library.
The creation of a Noder.io plugin can be useful to re-use code easily across multiple projects.
Example
/**
* Initialization for use as a standalone module.
* @return {Noder} New `Noder` instance
*/
module.exports = function blog() {
var noder = require('noder.io');
// also you can create a new instance directly:
// var noder = new noder.Noder();
return module.exports.__noder(noder.createNoder());
};
/**
* Init `blog` plugin.
* @param {Noder} noder `Noder` instance
* @return {Noder} Current `Noder` instance
*/
module.exports.__noder = function blogPlugin(noder) {
// create config object only if not exists
noder.$di.addOnce('config', {}, true);
// sub-modules of blogPlugin
// that add features to the instance of Noder
noder.use(require('./api/article'));
noder.use(require('./api/comment'));
noder.use(require('./api/admin'));
// Always return the instance of Noder to allow chaining
return noder;
};
See also, another example on Github.