How to use nodemon with express js while npm start?
Asked Answered
A

7

13

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.

Atahualpa answered 7/8, 2017 at 10:27 Comment(0)
R
9

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

Relique answered 25/1, 2021 at 13:12 Comment(0)
A
6

For this firstly install nodemon globally as

npm install -g nodemon

Now go to your express.js project directory and in that open the package.json file. In the package.json file change "start": "node ./bin/www" to "start": "nodemon ./bin/www"

Now run your app using npm start

Atahualpa answered 7/8, 2017 at 10:27 Comment(2)
Why question and answer yourself ?Mosque
You don't need -g for this. Just use npm install -S nodemonSplendiferous
F
4

Install what you need:

npm install express nodemon

Ensure to set up express, server and others properly:

const express = require('express');
const app = express();
...

Add "start": "nodemon index.js", to the "scripts" in your package.json file:

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

Run npm start on your terminal.

Ferous answered 4/3, 2023 at 14:43 Comment(0)
B
2

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"
}
Broadcaster answered 2/11, 2018 at 20:31 Comment(0)
C
1

Another solution: after install nodemon just run your app with nodemon start .

Check answered 20/3, 2018 at 11:20 Comment(0)
A
1

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

Antediluvian answered 14/9, 2021 at 3:39 Comment(0)
S
1

You just need to npm install nodemon or npm install -g nodemon and then nodemon .\[your-app-name].js. Remember for each time you make any changes to your code press Ctrl + S to save the changes so nodemon can recognize changes and apply them. To SumUp There is two steps to use nodemne:

//step #1
npm install (-g) nodemon
//step #2
nodemon .\[your-app-name].js
Sadden answered 25/7, 2023 at 15:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.