No Demon!
Developing a node.js based service?
Fed up with manually restarting your app every time you make a change?
If you’ve answered yes to both questions give nodemon a try.
nodemon
will monitor the files in the directory, and in case of a change - it will automatically restart your node application.
Installation
$ npm install -g nodemon
Usage
Since nodemon is a replacement wrapper for node that watches for changes, just replace node
with nodemon
when you run your script:
$ nodemon my_service.js
In case you need a manual restart of your app type rs
followed by a return
, instead of stopping
and restarting nodemon.
I recommend adding a dev
script under npm scripts in package.json
file:
{
"scripts": {
"start": "node my_app.js",
"dev": "nodemon my_app.js"
}
}
There are other features I found useful:
- Using config files or
nodemonConfig
in the package.json file - Specifying extension watch list:
nodemon -e js,json
- Monitoring multiple directories:
--watch
flag per directory watched
Note: I plan to cover debugging with nodemon in a separate post.