34

I installed NodeJS (4.4.5) and then proceed to install nodemon (1.9.2) as well, I follow all the instrucctions of instalation (npm install -g nodemon)

I created a new folder, inside I have my server.js with some basic code:

var http = require('http');

http.createServer(function (request, response){
    response.writeHead( 200, {'Content-Type': 'text/plain'} );
    response.write("Hello world");
    response.end();
}).listen(3000, 'localhost');

console.log('http://localhost:3000');

So when I run in my console "nodemon server.js" I get this:

[nodemon] 1.9.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node server.js`
http://localhost:3000

(Which means that is running fine)

But when I make some changes in my server.js, It doesn't restart the server

What could be the issue?

BrianCas
  • 749
  • 3
  • 12
  • 22
  • seems to work ok for me using same versions and code. you sure you saved the file? :) – Robbie Jun 03 '16 at 20:21
  • 1
    yes, I'm constantly making changes and saving, the only way I was able to restar my server was typing 'rs', like it says there – BrianCas Jun 03 '16 at 21:11
  • maybe you're running in a vm? i've had issues in the past with that https://github.com/remy/nodemon/issues/146 – Robbie Jun 03 '16 at 21:14

12 Answers12

85

In some networked environments (such as a container running nodemon reading across a mounted drive), you will need to use the legacyWatch: true which enabled Chokidar's polling.

Via the CLI, use either --legacy-watch or -L for short:

nodemon -L

Sergey Ivchenko
  • 1,497
  • 12
  • 11
  • 4
    This is what solved my issue when running the server in a vagrant box with source files shared with the host. – unexplored Feb 14 '18 at 18:09
  • This also resolved my problem when running my node in a vagrant box. Thank you – MrD Mar 17 '18 at 22:33
  • 3
    This solved my problem when working with WSL2 (Ubuntu18.04). – Ñhosko Aug 11 '20 at 12:12
  • i had the same problem with monitoring a directory tree on a chromebook linux container. thank you, your solution fixed it. – alex May 21 '22 at 09:01
12

I had the same issue on nodemon 1.9.2 : 0 files were watched by nodemon

(try verbose mode nodemon server.js -V to get more information)

After some research, this issue was due to my root directory name : My root directory was named "mysite.git" thus nodemon was watching 0 file. I had renamed my root directory without the dot and nodemon now works as expected.

Remove all special characters from your root directory and nodemon should work as expected.

MrP
  • 1,408
  • 18
  • 23
  • 1
    Also remove all special characters from your project *path directory*. – Francute Jun 14 '17 at 05:06
  • I had `./src/index.js` and had to remove the `./` from the beginning to make it actually watch the file! – Mahdi Mar 14 '18 at 13:46
  • my path to the root directory is relative too, and -L solved the problem. the problem was the root directory is on a virtual/linux container drive (on a chromebook). – alex May 21 '22 at 09:06
  • This lead me to figuring out that I needed to add extensions to watch! – derpedy-doo Oct 20 '22 at 19:42
8

You can try running like this nodemon -L yourapp.js, something like that:

"scripts": {
    "start": "node index.js",
    "dev": "nodemon -L index.js "
 }

And run command:

npm run dev

This worked for me!

1

I just hit what seemed to be the same issue where I would make changes to my code and save them but nodemon wouldn't restart my server. The only way I could update was via 'rs' in the console. I ended here looking for a solution but then decided to just re-install nodemon as there was no good explanation for why it wasn't working:

npm uninstall nodemon
npm install nodemon

After reinstalling the automatic restart on code change worked.

1

Edit the package.json file like this :

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

This may help you.
1

Nodemon uses SIGUSR2 signal for restarting the server, cross-check if your server is overriding the functionality of this process signal. In my case, I was using heapdump module, which was resetting this signal, hence I started the server using:-

env NODE_HEAPDUMP_OPTIONS=nosignal nodemon app.js

This worked for me.

Pavneet Kaur
  • 729
  • 7
  • 5
0

Just Make Sure to add to scripts -> start --legacy-watch ./app

"scripts": {
    "start": "nodemon --legacy-watch ./app  ./bin/www "
},
Shahbaz A.
  • 4,047
  • 4
  • 34
  • 55
0

I had the same problem. I tried uninstalling nodemon, didn't work. You can try and uninstall nodemon globally, if it works. It didn't work in my case, so what I did is I deleted all the node modules from my system. They will be located at C:/users/user/AppData/Roaming/npm. I even reinstalled node into my system and then installed nodemon, then it worked.

  • this sounds like a different issue, not just the nodemon lib – chris Feb 03 '22 at 12:50
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – chris Feb 03 '22 at 12:51
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/30978112) – kmp Feb 07 '22 at 23:15
0

I had the same problem and I solved it adding the path C:\Windows\System32 to the system environment, after that, I had to restart Visual studio code and it worked!...

Reference: https://www.youtube.com/watch?v=a9fIZViTNEA

ahmednawazbutt
  • 823
  • 12
  • 34
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Tyler2P Jul 06 '22 at 10:55
  • @Tyler2P thanks for the advice. Sure. I'll keep this factor in mind next time. – ahmednawazbutt Jul 21 '22 at 07:16
0

if you are on windows use Powershell, not WSL. If you want to use WSL, you have to move your project directory to the WSL home directory OR use nodemon -L on the command line.

Cobby
  • 11
  • 2
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 25 '22 at 08:28
0

solve it by adding the path

C:\Windows\System32

to the system environment

Source: https://www.youtube.com/watch?v=a9fIZViTNEA

-1

I found a solution on YouTube. So, the solution is:

  1. Copy this path:

C:\Windows\System32

  1. Go into 'computer/This Pc' properties then into 'Advance System Settings/System Settings'.
  2. Then click on 'Environment variable' Button.
  3. Then double click on 'Path' in User Variables section.
  4. Then click on 'New' and paste this path :

C:\Windows\System32

Elikill58
  • 4,050
  • 24
  • 23
  • 45