-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nodemon + Forever + Port Binding #30
Comments
I appreciate you opened this donkey's ago - but TBH I'd have to play with forever and nodemon myself to see this. My gut says that forever hasn't really exit properly (perhaps correctly so). Have you tried changing the order of apps, instead of nodemon monitoring forever, switch it around, put forever on nodemon, and run as:
That way forever ensures nodemon remains up, and nodemon will restart on file changes. That said, nodemon is designed to wait if there's a crash on the app.js - so it won't restart your app. If that's the case, I think you might need a custom fork of nodemon that doesn't hang on exceptions - and instead just exits fully and only restarts the app.js on file changes. |
Yes, the changes you recommended I think are what would need to happen here |
The only way I can see this working is if nodemon exits on a crash - I could add an option to exit on crash that way forever can reboot the nodemon + script combo - but I'd be wary you might get in a bit of a loop (that said - without nodemon you'd hit the potential loop I guess). If you confirm - I'll add it. |
. . Remy, with nodemon exiting, we can wrap nodemon on forever and it will work the same way I tried to achieve wrapping the forever on nodemon. Currently, if you wrap nodemon on a forever script, the "forever" part will never run: when you change a file nodemon will reboot the script and when a crash occur nodemon will wait a file change. . Thanks. |
I'm not really clear which way around you mean when you say "on". Can you show me command line examples. That said, I think what you (ideally) want is this:
The problem is this: forever forks itself as a daemon process, and the child process exits. Which is fine for nodemon now, as it'll sit and wait until there are file changes. When it picks up a change, forever is restarted - but since the forever child process actual did exit - it's just started (this line of code, the child is null). So forever is started again - which causes multiple versions of forever to run. However! If you wrap forever around nodemon with the --exitcrash flag it does work:
Now if any files are changed in the working directory, nodemon restarts the server.js. If server.js crashes (test it by killing the process by PID), nodemon exists and forever restarts everything. I think that's the right combo. |
. . Sorry I didn't make it clear enough (language barrier). I meant exactly that: wrap nodemon inside a forever process ("forever nodemon script.js"). But for that to work as we are discussing on the thread, nodemon must exit if a crash occur. |
I'll test this - and if that's the case I'm likely to remove this feature as it's bespoke to forever. |
. . Yeap. Forever seems to have incorporated this functionality (restarting on file change, while keeping the service running). . . Thanks for the attention on this subject, guys. |
when i use this ,it will show me err ::node:events:368 Error: listen EADDRINUSE: address already in use :::5000
|
. . Hi there. Currently I have a very specific setup in the machine running the app I'm working on. Sadly I don't have direct access to the server and I need the app to run as smoothly as possible, but I also need a way to update the code. Since I can't access the server to restart the process, I used forever (in Node.JS) to keep it running.
. . As I needed to update the server frequently, I wrapped the "forever.js" script (that runs my "server.js"--that runs a HTTP and Socket servers) in a nodemon process.
. . The thing is: as I change a file, the nodemon process restart the forever.js, but then the forever.js runs an infinite loop of error/respawn with the following error message:
{ stack: [Getter/Setter],
arguments: undefined,
type: undefined,
message: 'EADDRINUSE, Address already in use',
errno: 98,
code: 'EADDRINUSE',
syscall: 'bind' }
. . If I manually do a Ctrl+C and restart the nodemon command ("nodemon -d 6 forever.js") it start ok again (even when it's in the forever error loop), but as soon as I change a file, my script goes into the "address in use" error loop again. I don't know if nodemon is not actually closing the process and the port bind hangs or something... If you have any tips I would greatly appreciate it.
. . I though about not using the forever.js (running "nodemon -d 6 server.js" rather then "forever.js") because when starting this way the server restarts ok if I save a file, but I really need the forever.js to restart my server automatically if an error occurs because I can't afford the downtime until I manually upload a file again (so that nodemon restart my server).
. . PS: it is worth mentioning that my server restarts ok when an error occurs if I run "node forever.js" directly, without "nodemon", so the problem seems to be using both of them together.
. . Do you have any tips?
The text was updated successfully, but these errors were encountered: