It’s very painful to restart the server every time when the code changes. Nodemon lets you restart the server automatically whenever the code changes. Now you don’t need to restart the server every time the code changes it will do it for you. Just install nodemon and forget about it.
So how would you install it?
Just run the command :
npm install nodemon -g
This will install nodemon on your computer globally as -g
is provided in the command.
When you start the server you rather than using this command npm start
or node app.js
now you just have to use
nodemon .
or
nodemon app.js
This will start the server for you and when any code changes within the directory it will restart it automatically.
Here is a screenshot:
Nodemon Advanced Options:
There are more options available with it.
In your package.json file, there should be a start script like this:
{
. . .
"scripts": {
"start": "node app.js"
}
. . .
}
While server is running and you want to restart the server manually, instead of stopping it and again starting just write rs
and press enter.
Here is the official documentation page where you can find plenty of options designed for you.