Nodemon will allow you to start your node.js project and make changes without manually shutting down and restarting your server.
Many people are scared of installing nodemon globally, so here’s a guide to install nodemon locally in your node.js project.
Step 1: Install nodemon
$ npm install nodemon --save-dev
Step 2: Update your npm scripts object in package.json
"scripts": {
...
"start": "npx nodemon index.js
}
Note: If you used the express generator you will change "nodemon index.js"
to your entry point into your server, which is likely “nodemon ./bin/www"
Step 3: Run your new npm script
$ npm start
Congrats!
Now our JavaScript changes will restart your server automatically
Bonus (how to restart nodemon with “rs”)
* Note, many frameworks compile and cache templates so changing your html/jade files WILL NOT restart your server. Instead of closing and re-running npm start
, type rs
into your terminal.