All Articles

Using nodemon

During development it is often the case you will be making changes to your source code and you would have to stop and start your server each time after a change is made. As you can imagine this could get extremely slow and that is where nodemon will help you.

The package nodemon monitors for any changes in your source code during development and will automatically restart your server.

Installing nodemon

Nodemon can be installed globally in your system via the following command

npm i -g nodemon

I don’t like to do it this way though. I feel it is better to install it as a dev dependency with the following command

npm i -D nodemon

Using nodemon

Once installed we can update the start script to use nodemon instead of node. To do this let’s update our package.json file as follows

"scripts": {
    "start": "NODE_ENV=production node index.js",
    "dev": "NODE_ENV=development nodemon index.js"
  },

You probably want a dev script and a start script. The dev script will start the development server using nodemon and the start script will start the production server without nodemon.

One more thing

Using nodemon will will make your development go faster as you wouldn’t have to stop and start the server after each change.