jsplugs
Dead-stupid init.d-like plugin manager for node.js.
$ npm install jsplugs
Usage
jsplugs()
Returns a jsplugs object that contains plugs.
jsplugs.require(...)
Loads plugs into the jsplugs object.
Returns jsplugs.plugs
.
jsplugs.plugs
Returns a hash of all the plugs loaded, in order. Each plug has an ordinal. Ordinals are a numeric prefix
to plug filenames (e.g. the ordinal of 010.xyz.js
is 010). Files without an ordinal are always last.
Using as Express Middleware
This example shows how to use jsplugs to plug in middleware into an express server. jsplugs fits well here because it supports ordering using ordinal prefix.
Given the directory structure:
- ./middleware
- ./middleware/050.cors.js
- ./middleware/100.auth.js
- ./middleware/120.log.js
- ./middleware/200.app.js
- ./middleware/999.errors.js
var express = ; // create an instance of `jsplugs` and load all the plugs under ./middleware// now middleware contains an ordered hash of all the plugs and their require()ed payload.var middleware = ; var server = express;for var mw in middleware console; server; server;
Running:
$ node express.js &[2] 65761using authusing logusing appusing errorsusing cors $ curl http://localhost:8080in authin login appin errors
License
MIT