3.5 Restarting App with Nodemon

  1. It is annoying that we need to rerun the app every time we make change in their source code. A better way to solve the problem is use nodemon to run our node.js app. Basically, whenever you make a change, nodemon automatically rerun your app.
  2. Install nodemon by npm. First, go to https://nodemon.io/ for documentation. Note: this module is a little different than the one we use earlier, lodash. Lodash got installed and added into our package.json. It means later we are able to require the module in our app.js file. nodemon however works a little differently. It is a command line utility that gets executed from the terminal. It is going to be a completely new way to start our application.
npm install nodemon -g

-g indicates nodemon is a global untility of your machine. Then, this command can be used anywhere in your machine and does not need to be in your project folder.
To use nodemon to run our app, we type

> nodemon app.js
[nodemon] 1.17.5
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node app.js`
starting app...
Sarting notes.js
[nodemon] clean exit - waiting for changes before restart

Now, whenever you make change to app.js, nodemon will rerun your app.

Isn’t it awesome?