auto-restart on crash
waits for file changes
That's kinda the point of nodemon - otherwise nodemon would send your script into a loop during development!
鈥ut if you really want to, you can do this (assuming non-Windows):
nodemon -x 'node app.js || touch app.js'
Otherwise, I'd recommend forever if you need something to keep restarting over and over regardless of the cause of crash.
Kind of late for this, but another alternative to forever is pm2.
You can use pm2 start server.js --watch
which will
or just make a
sart.bat
file and write inside of it :
:a
node index.js
goto:a
it shoud work
While running app.js through nodemon, which is creating a server and routing through pages,
it is auto restarting.
below is the output im getting,
nodemon] starting node app.js
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] starting node app.js
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
please let me know if any changes needs to be done
@nadim-khan , it sounds like your application is writing or touching a file that triggers the restart.
@pcnate Code is running fine on using command "node app.js".
although sometime it run fine but most of the time im getting the above error.
Still looking for changes.
of coarse the code works fine, but do you write to files?
@pcnate nope
I was having the same issue and could not figure out why nodemon would not restart and it was for 2 reasons.
Go into the file that nodemon is watching and save it and the server restarts! Hopefully that is somewhat helpful, worked for me!
Error Message
[nodemon] app crashed - waiting for file changes before starting...
[nodemon] restarting due to changes...
[nodemon] starting `babel-node src/index.js`
events.js:165
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::4000
at Server.setupListenHandle [as _listen2] (net.js:1346:14)
at listenInCluster (net.js:1387:12)
at Server.listen (net.js:1475:7)
at /Users/dhallan/Desktop/react-developer-course/graphql-udemy/graphql-basics/node_modules/graphql-yoga/src/index.ts:380:22
at new Promise (<anonymous>)
at GraphQLServer.start (/Users/dhallan/Desktop/react-developer-course/graphql-udemy/graphql-basics/node_modules/graphql-yoga/src/index.ts:378:12)
at Object.<anonymous> (/Users/dhallan/Desktop/react-developer-course/graphql-udemy/graphql-basics/src/index.js:61:8)
at Module._compile (internal/modules/cjs/loader.js:654:30)
at loader (/Users/dhallan/Desktop/react-developer-course/graphql-udemy/graphql-basics/node_modules/babel-register/lib/node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/dhallan/Desktop/react-developer-course/graphql-udemy/graphql-basics/node_modules/babel-register/lib/node.js:154:7)
Emitted 'error' event at:
at Server.emit (events.js:180:13)
at Server.emit (domain.js:422:20)
at emitErrorNT (net.js:1366:8)
at process._tickCallback (internal/process/next_tick.js:178:19)
at Function.Module.runMain (internal/modules/cjs/loader.js:697:11)
at Object.<anonymous> (/Users/dhallan/Desktop/react-developer-course/graphql-udemy/graphql-basics/node_modules/babel-cli/lib/_babel-node.js:154:22)
at Module._compile (internal/modules/cjs/loader.js:654:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
at Module.load (internal/modules/cjs/loader.js:566:32)
at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
[nodemon] app crashed - waiting for file changes before starting...
You could also delay restart if you don't want nodemon to restart immediately.
nodemon -x 'node app.js || (sleep 10; touch app.js)'
@remy if you check forever's github page now they say "For new installations we encourage you to use pm2 or nodemon"
Most helpful comment
That's kinda the point of nodemon - otherwise nodemon would send your script into a loop during development!
鈥ut if you really want to, you can do this (assuming non-Windows):
Otherwise, I'd recommend forever if you need something to keep restarting over and over regardless of the cause of crash.