Nodejitsu

Save time managing and deploying your node.js app

Nodejitsu has joined GoDaddy

We are excited to join GoDaddy to help spearhead their largest Node.js product: Website Builder. Please read our blog post to learn more about customer transition plans and our continued support for Open Source within the node community.

Want to know all the details?
Read the full blog post or read the GoDaddy Announcement.

npmawesome: OS services made easy with ndm

About the author

Name
Location
Worldwide
nodejitsu nodejitsu

Other popular posts

- Scaling Isomorphic Javascript Code - Keep a node.js server up with Forever - Package.json dependencies done right
- npm cheat sheet - 6 Must Have Node.js Modules

This is a guest post from Alex Gorbatchev over at npmawesome.com. Nodejitsu loved what npmawesome.com was doing 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.