Using Nodemon

When developing a webapp with nodejs. It can be a pain having to restart the webserver after every change.

Nodemon is a package that monitors your code files for changes, and as soon as they change, it stops and restarts the webserver and takes the load of manually restarting off of your shoulders.

To use it, first you need to install nodemon as a development dependency.

Use the following command.

> npm install -D nodemon

Once it’s installed you need to go to your package.json file and add a new script, you can name it whatever you like but lets call it dev for now and give it value nodemon index like so, assuming index.js is the entry point for your app.

...
"scripts": {
    "dev": "nodemon index"
}
...

Then it’s just a matter of running

> npm run dev

where dev is the name of the script specified in package.json file.

That’s it. In order to stop the process you can simply do Ctrl or Command + C to exit.

Leave a Reply

Your email address will not be published. Required fields are marked *