Supervising Node.js

written on Friday, January 14, 2011

I managed to get about one hour into Node.js web development (trying out Express, to be precise), before fustration with the lack of auto-reloading during deveopment overcame me...

Auto-reloading‽

While it seems fairly common for Python web frameworks to have a auto-reload feature; reloading your application whenever you changed a file. Yet it doesn't really seem to have caught on in the Node.js world. But as none of the Node.js web frameworks seem to have this feature, I rather suspect it is has to with Node.js itself, rather than the web frameworks culture within Node.js.

A quick tour on the interwebs seem to confirm this; there are quite a few Node.js patches floating around to add auto-reloading modules. Likewise, a bunch of external programs to monitor a directory for chaned files and re-start the application as needed.

node-supervisor to the rescue!

I dug around a bit and ended up trying out node-supervisor.

Once you have npm installed, it's quite simple:

npm install supervisor

And then, when developing:

# Old and busted
node your-app.js

# New hotness
supervisor your-app.js

This will promptly kill and re-start node your-app.js whenever something named *.js or *.node is changed in/below the current directory. It has options for tuning of all this default behaviour; try supervisor --help for details.

This entry was tagged Node.js