How to use nodemon with express js while npm start?

Viewed 12179

I want to use nodemon to automatically detect changes in my scripts in node.js project and restart when change detected. I have my project setup using express.js. How to use nodemon with express.js, so that when i type npm start, nodemon initiates itself.

5 Answers

Install nodemon as globally first, using these commands

`npm install -g nodemon` or `sudo npm install -g nodemon`

Next, ensure the "scripts" field of package.json file as this type

"scripts": {
    "start":"nodemon index.js",
    "devStart": "nodemon index.js"
}

If not as this type then change it and run npm run devStart

First of all you need to install nodemon, so give root privilege and install globally using following command:

sudo npm install nodemon -g

Then, go to your node project directory and open package.json and change "node" to "nodemon" in start field of scripts field.Ex:

"scripts": {
  "start": "nodemon ./bin/www"
}

first of all, install Nodemon

npm i nodemon

after this, go to package.json and add a new key/value into scripts, like this

  "scripts": {
       "dev": "nodemon src/index.js"
      },

so now just start you app with npm run dev

Related