This post was written for Nodejitsu blog and is crossposted here. Nodejitsu loved what I was doing at npmawesome.com and is now supporting the project.

ndm (GitHub: npm/ndm, License: ISC) by Benjamin E. Coe of NPM Inc makes it easy to deploy a complex service oriented architecture by allowing you to easily install OS-specific service wrappers directly from an NPM package and currently supports Centos, OS X, and Ubuntu.

npm install ndm

Usage

Using ndm is pretty easy. The most important thing to remember is that it tries to run a module from node_modules folder, not a local script. The github example repository has node_modules/example-service/index.js file and this is the file that runs.

Now that we have this out of the way, configuring a service is as easy writing a tiny service.json file.

{
  "example-service": {
    "description": "Example which describes how to use the ndm module.",
    "scripts": {
      "start": "./index.js"
    },
    "processes": 4,
    "env": {
      "DELAY": "3000"
    }
  }
}

The node_modules/example-service/index.js itself looks like this:

#!/usr/bin/env node

var counter = 0;
var delay = +process.env.DELAY || 5000;

console.log('Using ' + delay + 'ms delay...');

function ping() {
  console.log(process.pid, counter++);
  setTimeout(ping, delay);
}

ping();

You can then run ndm install followed by ndm start. All output will be redirected to a local logs folder. The above example configures four processes and so you should see four log files. Notice the DELAY env variable in the config. That gets passed to our service and overrides default 5000ms delay.

To make installing and starting of your service automatic (assuming it’s getting deployed in your application infrastracture) just add postinstall hook to your package.json.