mods

mods is an evented module system for Node.js.

npm install mods
22 downloads in the last week
35 downloads in the last month

mods

mods is an evented module system for Node.js.

Usage

Installation

$ npm install mods

Example

index.js
var mods = new(require('mods'));
var hello = require('./hello');
var bye = require('./bye');

mods.load(hello);
mods.load(bye);

var result = mods.fire('$test');

console.log(result);
hello.js
exports.name = 'hello';
exports.$test = function()
{
    console.log('hello --> $test');

    // this will fire `hello$test` which is not hooked so nothing will happen
    this.mods.fire('test');

    return 'result from hello.js';
}
bye.js
exports.name = 'bye';
exports.$test = function()
{
    console.log('bye --> $test');

    // this will fire `bye$test` which is hooked so it will be called
    return this.mods.fire('test');
}

exports.bye$test = function()
{
    console.log('bye --> bye$test');
    return 'result from bye$test in bye.js';
}
Output
$ node index
hello -> $test
bye --> $test
bye --> bye$test
npm loves you