14

I have a pretty basic nodemon configuration. I'm fixing this legacy node 7 project that I inherited and trying to make the development process a little bit painful. First thing first, a proper restart-and-transpile process (since it's built using ES6 modules syntax).

This is my folder structure:

- src
  |- index.js
- dist
  |- index.js
- index.js
- nodemon.js

I run nodemon as "start:dev": "nodemon index.js"

Here's it's content:

// index.js
if (process.env.NODE_ENV === 'production') {
  require('./dist/index.js');
} else {
  require('babel-register')({});
  require('babel-polyfill');
  require('./src/index.js');
}

The idea is that the code is transpiled on runtime, so that I don't have to stop server, re-transpile, start server manually, as I have been doing before.

Last but not least, nodemon config

// nodemon.js
{
  "restartable": "rs",
  "ignore": [
    ".git",
    "node_modules/**/node_modules"
  ],
  "verbose": true,
  "watch": [
    "src"
  ],
  "env": {
    "NODE_ENV": "development"
  },
  "ext": "js json"
}

I took this setup from MERN, and I think it should work. However, when I made a change and save, it goes:

[nodemon] files triggering change check: src/index.js
[nodemon] matched rule: /Users/me/project/path/src/**/*
[nodemon] changes after filters (before/after): 1/1
[nodemon] restarting due to changes...
[nodemon] src/index.js

(stuck here. it never restarts)

I've been checking the code, and the only thing that I'm unfamiliar with, that maybe be causing it I can think of would be a child_process.execFileSync() call, that will call a java tool; and a connection pool with mysql.createPool() (mysql package).

Tried both in Node 7.5 and Node 8.9. Any idea of what could be wrong?

Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206
  • it's a long shot, but did you ever find a solution to this? i'm having the same problem [here](https://stackoverflow.com/questions/67992086/nodemon-restarts-but-saved-changes-to-index-js-not-reflected-in-output). – sigil Jun 16 '21 at 19:24

20 Answers20

10

I am using window 10, and I faced this issue after I accidentally removed my %PATH% variable. Try adding these three paths if it is the case:

C:\Windows; C:\Windows\system32; C:\Windows\System32\Wbem;

Liu Ting Chun
  • 109
  • 1
  • 3
  • Well I did the same mess and this helped me fix it! 10x – Zhivko Nikolov Oct 20 '22 at 21:47
  • the Path should START with this(it didn't work for me when I paste it at the end of Path): %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0 – Sur Khosh Jan 19 '23 at 18:05
6

I was using windows 10, and I faced the same isuue. I used the supervisor instead of nodemon and it's working perfectly.

Run the below command :

npm install supervisor -g

supervisor src/index.js

5

Add the below path in the environment variable. It will solve your problem. %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\wbem;

5

For those who still do not have an answer, I reinstall an older version and it works

like "npm i -g nodemon@1.19.0"

4

I was using windows 10, and I faced the same issue. I used the supervisor instead of nodemon and it started working fine for me.

Run the below command :

npm install supervisor

and in package.json add these below lines of code in the scripts key

"scripts": {"start": "supervisor app.js"}
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Belal
  • 41
  • 1
  • This is the only solution that worked for me, I tried every solution on the web to fix nodemon, looks like nodemon is a no go anymore for windows users, this is the way to go – Georges D Jun 18 '23 at 23:00
3

Use below two commands:

npm install supervisor -g
supervisor src/index.js
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Saurabh Mishra
  • 215
  • 3
  • 8
1

I solved a similar issue before. I did the following things and it did work for me.

  1. npm start run:dev

  2. nodemon npm start run:dev

what is does is first i started server normally and then i used nodemon.

Shailesh Bhokare
  • 552
  • 1
  • 5
  • 13
0

type : ps aux | grep node or ps aux | grep port(e.g 3000)

and find the process copy its processId then type in terminal kill -KILL processId

it will stop your process by force than again start server

Ali Raza
  • 9
  • 3
0

Try executing

npm -g uninstall nodemon

then

npm -g install nodemon

That fixed it for me.

holydragon
  • 6,158
  • 6
  • 39
  • 62
0

Check whether you place your code in location without write permission. (Especially who put on Desktop) If no, please move the folder to other place with write permission. Or change the folder permission.

Edward
  • 1
0

By default, nodemon looks for the .js file. And due to the link of other extn files with your index.js file, it couldn't restart.

node index.js -e js,hbs,html

You can mention all the extensions which are linked with your index.js file

Hope it works for you. Thanks

0

Nodemon is now considered to be in stale situation.So its alternative npm package supervisor can be installed globally by npm i supervisor -g and be used as supervisor filename.js

Harsha jk
  • 81
  • 2
0

go to my computer's properties, click on system protection then click on advanced then click on Environment variables . There Two types of Variables. user variable and system variable. in system variable click on path then click on edit ,click on new (add three variables) %SystemRoot%\system32; %SystemRoot%; %SystemRoot%\System\Wbem then click ok .Rerun your cmd then run .it works

0

Supervisior is an alternative for nodemon. It worked for me

  1. npm i supervisior -g
  2. supervisior app.js
Rupak
  • 529
  • 6
  • 16
0

In The Package.Json File Add Start Script As

"nodemon": "nodemon dev-server.js"

and Start The Server As

npm run nodemon
Majid Hajibaba
  • 3,105
  • 6
  • 23
  • 55
0

When I using the latest version of nodeJS, it won't work. But when I change back to 10.15.0, it works normally.

高欣平
  • 172
  • 2
  • 8
0

Make sure nodemon isn't watching a file that you are writing to when the server starts up. You can set nodemon to ignore that (those) file(s) using the --ignore flag

for example

nodemon index.js --ignore 'something/*.json'
Jason
  • 2,280
  • 23
  • 22
0

2022 update for windows 10

Go to This Pc -> properties -> Advance System Settings -> Environment variable -> User Variables.

Double click 'path' and create 'New'. Then add this path

C:\Windows\System32

Note: Make sure to close and restart your terminal.

Dinith Rukshan Kumara
  • 638
  • 2
  • 10
  • 19
-1

This works for me;

Delete these directories; C:/Users/{user}/AppData/Roaming/npm and C:/Users/{user}/AppData/Roaming/npm-cache and re-installed global npm modules.

Sheers!!

-1

open cmd as administrator and write nodemon [namefile.js]

yazid
  • 11