Hot reload for node.js servers on code change
If you are working with node.JS, you may experience the need to restart the node server as soon as a file has changed.
There are plenty approaches for this field. One is, to parse for all require statements in the code and watch those files then.
I took a different approach, which could be described by this linux command:
It searches for all .js files in the folder and restarts the server, as soon as one of those changed. Very easy, but yet powerful.
To use it, just copy: run_dev_server.js into your server directory.
This script expects your server script to be called run_server.js. If you want to change it, just change the line.
Instead of running your server with
you now start it with:
That's it!
This feature is of course part of the spludo framework's 1.0-dev version. In spludo, you can use
instead of
to achieve a hot reload on each .js change.
Update 2010/08/27: Wilkerlucio created a version for hot reloading coffee-scripts.
Messages
Or you could use nodemon thats in npm?
Hello.
I've adapted your script for Windows: https://github.com/kuchumovn/node-js-development-mode
Doesn't recurse into directories. This can be easily done with fs.readdir.
You might need to start node automatically on boot, you can do it with upstart integration. you can find it at:
http://github.com/shimondoodkin/nodejs-autorestart
For me this looks like hot restart, for hot reload see:
http://github.com/shimondoodkin/node-hot-reload
Also I like my node-inflow module:
http://github.com/shimondoodkin/node-inflow
wow spludo looks interesting.
Awesome. Alternatively:
this.process = child_process.spawn(process.ARGV[0], [process.ARGV[2]]);
Allows you do:
node run_dev_server.js my_actual_server.js


