dovetail 
Make your application pluggable!
Getting Started
To install the module, run the following in the command line:
npm i dovetail --save
Use within your application with the following lines of JavaScript:
var events = require('events');
var Dovetail = require('dovetail');
var MyApp = function (options) {
events.EventEmitter.call(this);
this.dovetail = new Dovetail(this);
this.dovetail.resolve('/path/to/middleware/*.js');
};
require('util').inherits(MyApp, events.EventEmitter);
Nothing else is required, but the middleware won't run until you
trigger them
MyApp.prototype.trigger = function (event, params, done) {
this.dovetail.runEvent(event, params, done);
};
Now you can drop a javascript file into your middleware folder and it'll be registered:
module.exports = function (app) {
var middleware = function (params, next) {
console.log('This is my custom middleware!');
console.log('event', params.event);
params.startTime = new Date();
next();
};
middleware.options = {
name: 'my-custom-middleware',
description: 'This is an awesome middleware that runs before the application starts.',
events: [ 'app:before:start' ]
};
var rtn = {};
rtn[middleware.options.name] = middleware;
return rtn;
};
Create a function for your app that will trigger some events:
MyApp.prototype.start = function () {
var self = this;
self.params = {};
self.trigger('app:before:start', self.params, function(err) {
if (err) {
throw new Error(err);
}
console.log('The app has started');
self.trigger('app:before:end', self.params, function (err) {
if (err) {
throw new Error(err);
}
console.log('The app has ended');
});
});
}
Contributing
Find a bug? Have a feature request? Please create an Issue.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality,
and run docs in the command line to build the docs with Verb.
Pull requests are also encouraged, and if you find this project useful please consider "starring" it to show your support! Thanks!
Author
Brian Woodward
License
Copyright (c) 2014 Brian Woodward, contributors. Released under the MIT license
This file was generated by verb-cli on May 01, 2014.