spinner

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

Spinner

Spin up node scripts bound to dynamic ports (forked from nploy)

$ npm install spinner

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(errroutechild) {
  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.

  • 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

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

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.

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

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

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

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

Run tests:

npm test

MIT/X11

Author (nploy): George Stagas (@stagas)

Author (spinner): Elad Ben-Israel (@eladb)