8

I have installed nodemon using command:

npm install nodemon -g

Having done that I changed "start": "node ./bin/www" to "start": "nodemon ./bin/www"

Output in Console on running npm start :

[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `nodemon  ./bin/www ./bin/www`
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `nodemon  ./bin/www ./bin/www ./bin/www`
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `nodemon  ./bin/www ./bin/www ./bin/www ./bin/www`
and so on....

Where am I going wrong? Please bear in mind that this is my 3rd day on nodejs so keep it simple.

Edit

 "scripts": {
    "start": "nodemon app.js"
  },

enter image description here

enter image description here

"nodemon app.js" seems to work since the console does not show any errors but then I am unable to run the application. However if I change it back to node ./bin/www it would work.

SamuraiJack
  • 5,131
  • 15
  • 89
  • 195

4 Answers4

2

Try to downgrade requirements. This helped me.

npm install nodemon@1.0.0 -g

I reproduced this issue in docker image (node:alpine) with nodemon >1.2.0 100%. And v1.1.0 and v1.2.0 have some strange issues too.

I checked only minor releases (w/o checking patchlevels e.g. 1.2.1, 1.2.2 and others)

So. 1.0.0 is old, but works well.

On my host Mac I have nodemon@1.11.0 installed globally. Sometimes I have this issue and sometimes I don't. This is somehow connected with pwd and nodemon.json file. But I'm not sure.

I found a bug report related to this problem.

akaRem
  • 7,326
  • 4
  • 29
  • 43
1

You are watching a file that doesn't exist and this will cause an infinite loop.

In your case, you are running ./bin/www and looking at you IDE screenshot you have a ./bin/www.js

That's why nodemon app.js doesn't error. Although I can't guaranty it's going to work try nodemon ./bin/www.js

Then, without looking at the code, I'm not sure why you can't connect your application that way.

For more info check @matt answer and nodemon docs.

Marco
  • 59
  • 10
0

You don't need to tell nodemon what folder to watch. You only need to tell it to run your main application and it will automatically watch all the nested folders and files.

eg. nodemon app.js (if app.js is your application)

Also. You can optionally create a nodemon.json file in the main body of your application to house config information for nodemon. Not really related to your queestion. But good to have :)

Here is what mine looks like:

{
  "ignore": ["data/*.json", "/node_modules/", "README.md"]
}
matt
  • 1,680
  • 1
  • 13
  • 16
  • I changed it to `"start": "nodemon app.js"` , it seems to have fixed the recursion issue since console now says "clean exit -waiting for changes" but I am not able to connect anymore "This site can’t be reached" – SamuraiJack Feb 18 '17 at 17:19
  • Edited my question – SamuraiJack Feb 18 '17 at 18:13
  • What port are you running your application on? Is it possible you messed up what port your trying to view the app on? Also, could you post a pic of your console and what it says when you write: `npm start`? – matt Feb 18 '17 at 20:21
  • I have added the console in my question. – SamuraiJack Feb 19 '17 at 05:12
  • Clean exit means your application is exiting after running. Do you happen to have a `process.exit(0)` somewhere in your code? – matt Feb 19 '17 at 19:47
0

Try with this :

npm i -D nodemon

in package.json add:

"scripts": {
    "start": "nodemon index.js",
  }

This executes the file index.js that is in the root of your app node. For example:

app/
node_modules
index.js

try again:

npm start

Xavier
  • 15
  • 6