BrianCas
BrianCas

Reputation: 789

NodeJS - nodemon not restarting my server

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?

Upvotes: 36

Views: 43761

Answers (13)

Mukul Data
Mukul Data

Reputation: 1

Steps for Windows

  1. Navigate to C:\Windows\System32.

  2. Open the Control Panel and go to Edit the system environment variables.

  3. In the Environment Variables window:

    • Under User variables, locate the variable named Path and click Edit.
    • Click New and add the following path:
      C:\Windows\System32
      
  4. Click OK to save your changes.

  5. Close your Visual Studio Code terminal and reopen it.

Upvotes: -3

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!...

Upvotes: -1

Abdul jawad Azizi
Abdul jawad Azizi

Reputation: 1

try to use "node --watch"

Upvotes: 0

Sarthak Chouksey
Sarthak Chouksey

Reputation: 1

solve it by adding the path

C:\Windows\System32

to the system environment

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

Upvotes: -2

Cobby
Cobby

Reputation: 19

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.

Upvotes: -1

webdev1903
webdev1903

Reputation: 1

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.

Upvotes: 0

Mehedi Hasan Shifat
Mehedi Hasan Shifat

Reputation: 720

Edit the package.json file like this :

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

This may help you.

Upvotes: -2

Pavneet Kaur
Pavneet Kaur

Reputation: 787

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.

Upvotes: 1

Alejandro Pérez
Alejandro Pérez

Reputation: 231

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!

Upvotes: 11

Kellen Preston
Kellen Preston

Reputation: 105

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.

Upvotes: 0

Subrata Sen Sr.
Subrata Sen Sr.

Reputation: 1

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

"scripts": {
    "start": "nodemon --legacy-watch ./app  ./bin/www "
},

Upvotes: 0

Sergey Ivchenko
Sergey Ivchenko

Reputation: 1617

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

Upvotes: 93

MrP
MrP

Reputation: 1458

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.

Upvotes: 13

Related Questions