spinner

Spawns child processes and allocates `process.env.PORT` for each.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
spinner
400.3.410 years ago11 years agoMinified + gzip package size for spinner in KB

Readme

Spinner
Spin up node scripts bound to dynamic ports (forked from nploy)
$ npm install spinner

createRouter(opts) ###

Options:
range - Port range 7000..7099 time - Time to idle 15 debug - Output logs routes - Hash of routing pairs (source -> target) {} output - Determines how child process output is handled:
* __false__ - Will not capture child process output
* __"console"__ - Will pipe child process stdin/stderr to console.info/console.error
* __"process"__ - Will pipe child process stdin/stderr to process.stdin/process.stderr
Example:
var spinner = require('spinner');
var router = spinner.createRouter({ port: 5000, dir: '../test' });

router.setRoutes({
  'foo': 'a/index.js'
, 'goo': 'b/index.js'
});

router.getRoute('foo', function(err, route, child) {
  if (err) throw new Error(err);
  console.log('Use %s:%d to access "foo"', route.host, route.port);
  router.kill('foo', function(err) {
    console.log('"foo" is now dead');
    router.close();
  });
});

The router object has the following API.

Properties ###

range - Returns the port range configured in the router idletime - Time in seconds to wait without a call to ``getRoute`` before the process is killed options - Options object

setRoute(source, target), setRoutes(map) ###

target may be a path to a node.js script or an object with a script property (path to the script) and extra options passed to the forever module when starting the child process.
Update routes table with source -> script pair(s).

getRoute(source, callback) ###

Returns a route to a source. Callback is ``function(err, port, child)` where `port`` is the same port passed to the app in ``process.env.PORT``.

clearRoute(source), clearRoutes(map) ###

Deletes route(s). If ``map`` is if not provided, all routes will be deleted

kill(source, callback) ###

Kills the process associated with ``source`. `callback` is `function(err)``.

close() ###

Shuts down the router. Namely, removes the idle timer.

getchild(source), getpid(source) ###

Returns the forever child of a source or it's PID.

Testing ##

Run tests:
npm test

Licence ##

MIT/X11
Author (nploy): George Stagas (@stagas)
Author (spinner): Elad Ben-Israel (@eladb)