nodemon is showing restarting the server but not working when doing changes on files

Viewed 3659

I am using the nodemon package, but it is not restarting the server. It is only showing "restarting due to changes". But in youtube videos, I saw that it was showing "server running" status after that.

In my case, that was not showing. It simply shows "restarting due to changes", my work also does not update when I view it in a browser.

I read lots of related stack overflow questions but none of them helped me ... Installing them locally on my project as devdependent.noting also does not work.

I also tried changing the script tags in the package.json file.

While running, I used nodemon, npm start, nodemon app.js, nodemon lib/dev-server.js --delay 1, nodemon -L, and many more, but nothing helped.

================================================================================= edited question:

i am using vs code. trying to run my javascript code with express framework . i am using git bash terminal. whatever basic hello world code also cannot run with nodemon. the steps i have followed: node -v and npm -v is working on my bash terminal. i have created a basic hello world express app . using npm init npm install express --save

i am attaching my github repository of this testApp https://github.com/webdevshiv/testApp.git then the main problem is about nodemon.. installing nodemon: npm install nodemon --save-dev,also nodemon install -g in script tag : "scripts": { "start": "node app.js" }, code for running nodemon: nodemon app.js in my terminal while running this i am getting: (bash: nodemon: command not found)

but node app.js is working.... then using npx nodemon app.js it was showing-----

([nodemon] 2.0.4 [nodemon] to restart at any time, enterrs[nodemon] watching path(s): *.* [nodemon] watching extensions: js,mjs,json [nodemon] startingnode app.js Example app listening at http://localhost:3000 [nodemon] restarting due to changes... [nodemon] restarting due to changes... [nodemon] restarting due to changes... [nodemon] restarting due to changes.)

you can clearly see on first time it was listening to port but on next times when i do any changes it showing restarting. but not restarting.. before when i am posting this this was the case for using nodemon normally but now nodemon is not working ...

i am attaching my system environment variable path: C:\Program Files\MongoDB\Server\4.2\bin;C:\Program Files\Git\cmd; C:\Program Files\nodejs; C:\Program Files\nodejs\node_modules\npm

i am giving link for my vs code screenshots https://imgur.com/e6ViUaF https://imgur.com/eWOkG0V

3 Answers

Try adding the path of your system 32 ( in my case 'C:\Windows\System32') to environment variables.

It worked for me

$npm ls chokidar 

run the above command in the directory you have nodemon installed. This worked for me.

The advice from @Adeel is completely correct. This is how I tested the solution:

Clone your demo repository, enter the directory and install dependencies

$ git clone https://github.com/webdevshiv/testApp.git
$ cd testApp
$ npm install

Install nodemon (as described by you and the nodemon website [1])

$ npm install -g nodemon

Use nodemon as described on their website

Just use nodemon instead of node to run your code...

In our case that would be (as @Adeel suggested)

$ nodemon app.js

For me this starts nodemon with the following output:

$ nodemon app.js
[nodemon] 2.0.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node app.js`
Example app listening at http://localhost:3000

When I change anything in app.js now nodemon reloads the express server automatically.

To further improve the setup you could replace the start script in package.json so it looks like this:

  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon app.js"
  },

Now you can just use $ npm start to run nodemon.

[1] https://nodemon.io/

Related