EN
Node.js - how to restart application automatically with nodemon
0
points
In this article, we would like to show you how to automatically restart Node.js application with nodemon
.
This article is divided into 3 steps:
nodemon
installation- globally
- locally
- how to start script with
nodemon
, - how to add
nodemon
topackage.json
.
1. Installation
Global installation
with npm:
npm install nodemon -g
with Yarn:
yarn global add nodemon
Local installation
with npm:
npm install nodemon --save-dev
with Yarn:
yarn add nodemon --dev
2. Start script with nodemon
Let's say we have Express server setup in an index.js
file. If we installed nodemon
globally, we can start our script with nodemon
watching for changes with the following command:
nodemon index.js
We can pass in arguments the same way as if we were running the script with Node:
nodemon index.js 5000
Note:
If you installed
nodemon
locally go to the next part of this article.
3. Add nodemon
to package.json
Let's say we have Express server setup in an index.js
file. We can add nodemon
to the "scripts"
inside package.json
file in our project like this:
now we can start our script with nodemon
watching for changes with a simple command:
npm start