written on Thursday, February 24, 2011
A quick list of what Node.js modules I use for various development tasks in Node.js.
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.
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.
To be continued...