Moksedul Islam
Moksedul Islam

Reputation: 11

Nodemon not restarting: [nodemon] restarting due to changes

Nodemon not restarting: [nodemon] restarting due to changes... i use vs code if change my code but not update my code browser and show restarting use due to change loop

probelm:

[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
server is running at http://127.0.0.1:3000
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...

my code:

const http = require("http");
const PORT = 3000;
const hostName = "127.0.0.1";
const server = http.createServer((req,res) => {
    res.end("Welco my server  server");
})
server.listen(PORT,hostName, () => {
    console.log(`server is running at http://${hostName}:${PORT}`)
})

package.json:

  "name": "test",
  "version": "1.0.0",
  "description": "test 1",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon index.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.1",
    "nodemon": "^2.0.9"
  }
}

nodemon --verbos index.js

[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node --verbos index.js`
node: bad option: --verbos
[nodemon] app crashed - waiting for file changes before starting...

Upvotes: 1

Views: 15249

Answers (5)

Prateek Khandelwal
Prateek Khandelwal

Reputation: 1

I am facing the same problem. The solution to this problem is straightforward: run the file directly without specifying the file name.

For example, if your file name is main.js, don't just use main.js; instead, use the full path to your file, like "C:\\Users\\Desktop\\web D\\BackEnd\\CommonJS\\main.js".

run the command

nodemon "filepath"

nodemon "c:\\Users\\Desktop\\web D\\BackEnd\\CommonJS\\main.js"

Upvotes: 0

newtocodeing
newtocodeing

Reputation: 57

Try the following

1 - uninstalling and reinstalling

2 npm file.js --delay

But what really works for me is adding adding path of my environmental variable to C:\Windows\System32

Steps:

Advanced system setting ->environmental variable -> Path -> edit ->C:\Windows\System32

Upvotes: 0

Mike3166
Mike3166

Reputation: 1

In my case, after adding the system path in the environment "C:\Windows\system32;", it still appeared. But I recognized it seems in some first nodemon run. Try to save more will get the problem solved.

Upvotes: 0

K4S3
K4S3

Reputation: 163

This isn't a very technical fix but I managed to get my nodemon working as expected again.

First I ran npm cache verify which took a long time to run so I cleaned the cache by using npm cache clean --force, had to use the --force flag because npm will tell you there is no need to run the cache clean command as npm self cleans.

Then I just ran npm i [email protected] -g, the last stable build before nodemon version 2. Ran my npm run dev script and now all is well in the developer experience again.

Upvotes: 3

Dinesh Rout
Dinesh Rout

Reputation: 81

There is no need to add hostname in the server.listen method.

Upvotes: 0

Related Questions