Nondeterministic Polynomial Munchies
Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »


1.0.3 • Public • Published

Cleverstack Injector Module

NPM version GitHub version Dependency Status devDependency Status Code Climate Build Status Coverage NPM downloads

CleverStack Node Seed

NodeJS Dependency Injection for the CleverStack ecosystem, designed to work with or without CleverStack.


If you are using the CleverStack framework you do not need to install or setup the injector, CleverStack comes out of the box with the injector ready to use.


  1. Non-blocking and fully async
  2. Load's resources based upon name for you and injects dependencies
  3. Will never load the same resource more than once, it uses the one singular instance for all dependencies


npm i clever-injector

Setup injector instance

var CleverInjector = require( 'clever-injector' );

// You can add directories so that the injector can try to load the resources by name,
// this example presumes you have a folder called src with a file named Example.js
var injector = CleverInjector( __dirname + '/src', __dirname + '/config );

// You can add instances to the injector like this
injector.instance( 'config', config );
injector.instance( 'models', models );
injector.instance( 'db', db );

// You can get instances like this
var config = injector.getInstance( 'config' );

// You can inject functions and name them like this
    function( config, models ) {
        return {}; // Return whatever resource you are defining
    function( Resource ) {
        injector.instance( 'Resource', Resource );

Writing files

// src/Example.js
module.exports = function( db ) {
   return {};

Use injector

injector.inject( function( Example, models, config ) {
   // this function will be called asynchronously after all required modules are initialized and/or loaded.

For more details take a look at provided testsuite. There are all possible use cases.


npm i clever-injector

DownloadsWeekly Downloads






Last publish


  • avatar