Hot Code Loading in Node.js

2010-02-05 00:00:00 +0000 by Alex R. Young

In Hot Code Loading in

Blaine Cook describes how to dynamically reload code in node.js
projects. He's created a branch of node.js called
hotload that provides the feature.

Hot code loading uses sandboxes and caching to reload code when it
changes. If you had a web app and updated some files, it would
automatically reload the code for new requests.

His example looks like this:

var requestHandler = require('./myRequestHandler');

process.watchFile('./myRequestHandler', function () {
  requestHandler = require('./myRequestHandler');

var reqHandlerClosure = function (req, res) {
  requestHandler.handle(req, res);


Strictly speaking it's not as advanced as the way Erlang
but it could ease deployment and avoid abrupt process reloading.