Languages
[Edit]
EN

Node.js - how to restart application automatically with nodemon

0 points
Created by:
Dragontry
731

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 to package.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:

Add nodemon to package.json
Add nodemon to package.json

now we can start our script with nodemon watching for changes with a simple command:

npm start

References

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Node.js

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join