Home

aleafs edited this page Dec 6, 2012 · 10 revisions
Clone this wiki locally

About

pm is a graceful process manager for Node.js.

Api for Master, Api for Worker

Install

$ npm install pm

Usage

  • in master.js, run as master:
var app = require('pm').createMaster({
 'pidfile' : '/tmp/demo.pid',
});

app.register('group1', __dirname + '/http.js', {
 'listen' : [8080, 8081]
});

app.on('giveup', function (name, num, pause) {
  // YOU SHOULD ALERT HERE!
});
app.dispatch();
  • in http.js, run as worker:
var http = require('http').createServer(function (req, res) {
 res.end('hello world');
});

require('pm').createWorker().ready(function (socket, port) {
 http.emit('connection', socket);
});
  • example for express:
var app = require('express')();
app.get('/', function (req, res) {
  res.end('hello world');
});

var http = require('http').createServer(app);
require('pm').createWorker().ready(function (socket, port) {
 http.emit('connection', socket);
});