Automatically Restart Your Node.js Application

Many of us write code on Node.js, click [CTRL+S] to save the file but forget to restart the application.

If we don't forget to restart the application we will go in console and hit [CTRL+C] to stop the application and then restart it by pressing the [UP] arrow and [Enter].

Nodemon

You can automate this repetitive task and make your development process easier by using `nodemon`.

`nodemon` will watch the files and if any files were changed, the `nodemon` will automatically restart your node application.

First, you need to install `nodemon`:

npm install nodemon -g

Now, you should swap the `node` command for the `nodemon` command:

$ nodemon app.js
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node app.js`
[nodemon] restarting due to changes...
[nodemon] starting `node app.js`
Read about: How to set up a Node.Js development environment

If you need to manually restart your application, instead of stopping and restart `nodemon`, you can simply type `rs` on your console.

[nodemon] starting `node app.js`
rs
[nodemon] starting `node app.js`

Happy Coding!