Keeping Services Running with nodemon

Especially during development, it’s useful to have your Node.js application automatically restart when files change on disk. We saw a similar technique work well when running tests using Mocha back in ​Enabling Continuous Testing with Mocha​.

Short for Node Monitor, nodemon runs a Node.js program and then automatically restarts it whenever the source code changes or if the process terminates. To use it, first we have to install and save the dependency.

​ ​$ ​​npm​​ ​​install​​ ​​--save​​ ​​--save-exact​​ ​​nodemon@1.11.0​

Next, open your package.json file and add a new start command to the scripts section to override the default.

​ ​"scripts"​: {
​

Get Node.js 8 the Right Way now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.