childport

Launch child processes for services that bind to a specified port.

Launch child processes for services that bind to a specified port.

npm install childport

// parent.js 
var request = require('request')
  , childport = require('childport')
  ;
 
function finish (ep) {
  request('http://localhost:3001', function (erespbody) {
    if (e) throw e
    if (resp.statusCode !== 200) throw new Error('status not 200, ', resp.statusCode)
  })
}
 
var child = childport.cp(3001, finish).spawn('node', [__dirname+'/child.js'])
child.on('error', function (e) {throw e})
child.stderr.pipe(process.stderr)
// child.js 
var http = require('http')
  , childport = require('../')
  ;
 
childport.listen(http.createServer(function (reqresp) {
  resp.statusCode = 200
  resp.end('ok')
}))

This method is to be used in child process scripts. It will parse the specified port and call listen on the server it sent and, on success, let the parent process know it has finish so that it can resolve the specified callback.

Returns the server it was passed for easy chaining.

Returns a mocked child_process module that will launch the process with identifying information about the port to bind to.

Identical to core's child_process.spawn.

Identical to core's child_process.fork.

Identical to core's child_process.exec.

Identical to core's child_process.execFile.