Skip to content

Repository files navigation

Noder.io

Actual version published on NPMnpm module downloads per month

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:

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:

varnoder=require('noder.io');

Best practice, create an instance of Noder class for your project:

// ./api/index.jsvarNoder=require('noder.io').Noder;varapi=newNoder();// code body that constructs your APImodule.exports=api;

or shortcut:

// ./api/index.jsmodule.exports=require('noder.io').createNoder();

Use your API in another file:

varapi=require('./api');// load a pluginapi.use('pluginName');// create an item in the containerapi.$di.set('someItem','value of the item');// ...

Collection

Noder.io provides a class to handle a collection of items.

// create a collectionvaritems=noder.createCollection();items.set('keyName','key value');// keyName valueconsole.log(items.get('keyName'));// get all itemsvarall=items.getAll();// trueconsole.log(itemsinstanceofnoder.Collection);

See collection.

Dependency Injection

See dependency injection.

Lazy loading

noder.$require method provides a lazy require():

// define the property without loading the mongoose modulenoder.$require('mongoose');// falseconsole.log(noder.$require.isLoaded('mongoose'));// lazy loadingvarmongoose=noder.mongoose;// trueconsole.log(noder.$require.isLoaded('mongoose'));// trueconsole.log(noder.mongoose===require('mongoose'));

Aliases:

noder.$require('promise','bluebird');// trueconsole.log(noder.promise===require('bluebird'));

Custom loader:

// factory: promisify the "fs" modulenoder.$require('fs',function(){returnnoder.promise.promisifyAll(require('fs'));});fs.readFileAsync('./any-file.js').then(function(contents){console.log(contents);}).catch(function(err){console.error(err);});

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 {Noder} New `Noder` instance */module.exports=functionblog(){varNoder=require('noder.io').Noder;varnoder=newNoder();// or use the shortcut:// var noder = require('noder.io').createNoder();returnmodule.exports.__noder(noder);};/** * Init `blog` plugin. * @param {Noder} noder `Noder` instance * @return {Noder} Current `Noder` instance */module.exports.__noder=functionblogPlugin(noder){// create config object only if not existsnoder.$di.addOnce('config',{},true);// sub-modules of blogPlugin// that add features to the instance of Nodernoder.use(require('./api/article'));noder.use(require('./api/comment'));noder.use(require('./api/admin'));// Always return the instance of Noder to allow chainingreturnnoder;};

See plugins.

Unit Tests

Noder.io is fully tested with Unit.js and Mocha.

License

MIT (c) 2013, Nicolas Tallefourtane.

Author

Nicolas Tallefourtane - Nicolab.net
Nicolas Talle
Make a donation via Paypal

About

A lightweight and flexible core to create a scalable API. Starting a project quickly with a modular API ready to use. Works on Node.js and in the browser (only 7kb minified - 2kb gzipped).

Resources

Contributing

Stars

40 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages