Node.js modules

written on Thursday, February 24, 2011

A quick list of what Node.js modules I use for various development tasks in Node.js.

Package management:

NPM: Node Package Manager. You will need to bootstrap your installation, but after that, most packages can be installed rather easily:

npm install <packagename>
npm install <github-url>
npm install <local directory>

You can also get a list of npm's package list by issuing npm list. npm rm <packagename> and npm update are also quite handy for removing and upgrading (all) packages, respectively.

Web development
Express.js and node-supervisor.
Command-line parsing

Optimist. Both does some clever wrapping of both options and arguments. You can make some parts if it required, but for simple stuff, it's extremely simple to use:

#!/usr/bin/env node
var argv = require('optimist').argv;
var sys = require('sys');
sys.puts(sys.inspect(argv));

When run on the command-line, it makes some brave attempts to figure out what the user really meant:

>node script.js -s "short opt" --bool --long "longer opt" and then some other stuff

Turns into this handy object (esp. note the _ and $0 properties):

{ _: [ 'and', 'then', 'some', 'other', 'arguments' ],
  '$0': 'node ./script.js',
  s: 'short opt',
  boolean: true,
  long: 'longer opt' }

The module can do some verification for you, but it is still quite handy, just with it's default behaviour.

Utilities
Underscore is the go-to module, if you don't want to work with data in node and keep sane at any level.

To be continued...

This entry was tagged Node.js and web development