🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis
Socket
Book a DemoInstallSign in
Socket

noder.io

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

noder.io

Noder.io provides a lightweight IoC container to build the core of a scalable API. No dependencies, works on Node.js and in the browser (only 4kb).

npmnpm
Version
1.0.3
Version published
Weekly downloads
5.8K
-2.49%
Maintainers
1
Weekly downloads
 
Created
Source

Noder.io

Actual version published on NPM

Noder.io provides a lightweight and flexible core to create a scalable API of a lib, a module, an application or a framework.

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 4kb).

Quick start

See quickstart.

Usage

Get common instance of Noder:

var noder = require('noder.io');

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

// ./api/index.js
var Noder = require('noder.io').Noder;
var api   = new Noder();

// code body that constructs your API

module.exports = api;

or shortcut:

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

Use your API in another file:

var api = require('./api');

// load a plugin
api.use('pluginName');

// create an item in the container
api.$di.set('someItem', 'value of the item');

// ...

Collection

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

// create a collection
var items = noder.createCollection();

items.set('keyName', 'key value');

// keyName value
console.log(items.get('keyName'));

// get all items
var all = items.getAll();

// true
console.log(items instanceof noder.Collection);

See collection.

Dependency Injection

See dependency injection.

Lazy loading

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

// define the property without loading the mongoose module
noder.$require('mongoose');

// false
console.log(noder.$require.isLoaded('mongoose'));

// lazy loading
var mongoose = noder.mongoose;

// true
console.log(noder.$require.isLoaded('mongoose'));

// true
console.log(noder.mongoose === require('mongoose'));

Aliases:

noder.$require('promise', 'bluebird');

// true
console.log(noder.promise === require('bluebird'));

Custom loader:

// factory: promisify the "fs" module
noder.$require('fs', function() {
  return noder.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 = function blog() {

  var Noder = require('noder.io').Noder;
  var noder = new Noder();

  // or use the shortcut:
  // var noder = require('noder.io').createNoder();

  return module.exports.__noder(noder);
};

/**
 * 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 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

Keywords

ioc

FAQs

Package last updated on 20 Oct 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts