Change Your Node Script Without Restarting
Have you every wished you could change your node script and not restart the server? Restarting your node server after changing your script can get annoying. This is especially true if you’re in guess and check mode, changing and checking a lot. Luckily, there are a few tools to save you the pain.
Isaac Schlueter has created a node-supervisor. Install it with a quick npm:
sudo npm install supervisor -g
supervisor, instead of
node to start your app:
By default, this will run with these options:
DEBUG: Running node-supervisor with DEBUG: program 'app.js' DEBUG: --watch '.' DEBUG: --ignore 'undefined' DEBUG: --extensions 'node|js' DEBUG: --exec 'node'
There are other options for things like watching only specific extensions or not restarting on app errors.
Remy Sharp has created nodemon. It also is a quick npm install:
sudo npm install nodemon -g
Again, run with
nodemon instead of
By default, runs:
[nodemon] v0.6.23 [nodemon] watching: . [nodemon] starting `node app.js`
There are similar options here for what to watch.
Comparison of tools
Both tools will get the job done. Choose either. Both can specific directories or file extensions to watch. Both can run other executables (like forever, which is awesome, btw).
Both tools are circa 2010. Node-supervisor is the slightly older brother (by 8 months). Both projects seem to have slow, steady development development activity. What is there to add to tools that do their job already?
nodemon has a few more options. For example, it has explicit support for coffee-script. I like
supervisor more for silly reasons: I found it first, it works fine, feels better to type, and has fewer terminal command expansion conflicts.
Recently I have found one clear reason to use
nodemon doesn’t allow starting a process with node and monitoring coffee script files. The conditionals in the source code rule that possibility right out.
supervisor does this just fine with the command:
supervisor --extensions 'node|js|coffee' app.coffee
Another couple observations:
supervisordoesn’t have in-terminal colors
supervisorseems to be more explicit in its logging