Monday, January 31, 2011

Getting started with node.js

By now everyone has more or less heard of node.js.

Node.js is an exciting project that takes the super fast V8 javascript engine open sourced by Google and wraps it with an event oriented framework that allows it to process concurrent requests blazingly fast. Event oriented (using one of epoll, kequeue, /dev/poll, select) concurrency model is considered to be much superior to thread based concurrency model - point in case nginx vs Apache comparison.

Listed below are some resources that I found very useful to get started on node.js.
  • Main node.js page
    Introducuction to node.js. A must read to understand the architectural decisions behind node.js
  • Installation
    This page contains instructions to install node.js and npm (NodeJS Package Manager).
    If you plan to use node-inspector for debugging, install v 0.3.0 or later.
    I had trouble installing npm when I installed node in /usr/local. The npm install script complains loudly when invoked as sudo - rightly so as packages can run arbitrary scripts.
    Best approach I have found is to install node.js in a local directory as shown in this gist (node-and-npm-in-30-seconds.sh) and then install npm.
  • Npm
    Npm is NodeJs Package manager. Some links of interest : intro to npm, docs and a faq. Also here is a list of npm packages.
  • Express
    To simplify setting up a web server using node.js, use the Sinatra inspired Express framework. It is built on top of Connect. I came across an interesting thread regarding a node.js module called Nitrode which points out high memory usage of Connect when streaming large files.
    You can generate a skeleton app using express <appname>
    Very useful - details on the skeleton generated using the command above (scroll down half-way)
  • node-inspector
    Needs node.js > 0.3.0
    Read up on node-inspector at https://github.com/dannycoates/node-inspector and https://github.com/past/node-inspector
    npm install node-inspector

No comments: