Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Dead-stupid init.d-like plugin manager for node.js
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
samples
test
.gitignore
.npmignore
.travis.yml
LICENSE
README.md
main.js
package.json

README.md

jsplugs Build Status

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.

require('/path/to/plugs')
require('/path/to/plugs/myplug.js')
require([ 'dir1', 'dir2', ... ], ...)
require('dir1', 'myplug2.js', ...)

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 first.

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:

$ ls
./middleware
./middleware/050.cors.js
./middleware/100.auth.js
./middleware/120.log.js
./middleware/200.app.js
./middleware/999.errors.js

This loads all the plugs under ./middleware into the express server, in-order.

var express = require('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 = require('jsplugs')().require('./middleware');

var server = express.createServer();
for (var mw in middleware) {
    console.log('using', mw);
    server.use(middleware[mw]);
}

server.listen(8080);

Running:

$ node express.js &
[2] 65761
using cors
using auth
using log
using app
using errors

$ curl http://localhost:8080
in cors
in auth
in log
in app
in errors
500 Server Error

License

MIT

Something went wrong with that request. Please try again.