Noder.io
Noder.io provides a lightweight and flexible core to create a scalable API of a lib, a module, an application or a framework. Noder.io is inspired (among others) by Angular and Pimple.
It is useful for starting a project quickly with a modular API ready to use.
Noder.io (and any object built on top of Noder.io) integrates:
- dependency injection
- constructors of services, factories and providers
- lazy loading
- plugins system easy to use
No dependencies, works on Node.js and in the browser (only 7kb minified - 2kb gzipped).
Quick start
See quickstart.
Usage
Get common instance of Noder
:
var noder = ;
Best practice, create an instance of Noder
class for your project:
// ./api/index.jsvar Noder = Noder;var api = ; // code body that constructs your API moduleexports = api;
or shortcut:
// ./api/index.jsmoduleexports = ;
Use your API in another file:
var api = ; // load a pluginapi; // create an item in the containerapi$di; // ...
Collection
Noder.io provides a class to handle a collection of items.
// create a collectionvar items = noder; items; // keyName valueconsole; // get all itemsvar all = items; // trueconsole;
See collection.
Dependency Injection
See dependency injection.
Lazy loading
noder.$require
method provides a lazy require()
:
// define the property without loading the mongoose modulenoder; // falseconsole; // lazy loadingvar mongoose = nodermongoose; // trueconsole; // trueconsole;
Aliases:
noder; // trueconsole;
Custom loader:
// factory: promisify the "fs" modulenoder; fs ;
See lazy loading.
Plugins
Noder.io provides a plugin system to make a package works as a plugin for Noder.io and also as a standalone module or library.
Example of a Noder plugin:
/** * Initialization for use as a standalone module. * @return */module { var Noder = Noder; var noder = ; // or use the shortcut: // var noder = require('noder.io').createNoder(); return moduleexports;}; /** * Init `blog` plugin. * @param * @return */moduleexports { // create config object only if not exists noder$di; // sub-modules of blogPlugin // that add features to the instance of Noder noder; noder; noder; // Always return the instance of Noder to allow chaining return noder;};
See plugins.
Unit Tests
Noder.io is fully tested with Unit.js and Mocha.
License
MIT (c) 2013, Nicolas Tallefourtane.
Author
Nicolas Talle |
![]() |