Giter Site home page Giter Site logo

Nodemon + Forever + Port Binding about nodemon HOT 9 CLOSED

remy avatar remy commented on May 5, 2024
Nodemon + Forever + Port Binding

from nodemon.

Comments (9)

remy avatar remy commented on May 5, 2024

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:

forever nodemon app.js

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.

from nodemon.

mattapperson avatar mattapperson commented on May 5, 2024

Yes, the changes you recommended I think are what would need to happen here

from nodemon.

remy avatar remy commented on May 5, 2024

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.

from nodemon.

dnunes avatar dnunes commented on May 5, 2024

. . 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.
. . If you can add this option it would be perfect.

. Thanks.

from nodemon.

remy avatar remy commented on May 5, 2024

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:

nodemon -x forever start server.js

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:

forever nodemon --exitcrash server.js

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.

from nodemon.

dnunes avatar dnunes commented on May 5, 2024

. . 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.
. . Is that "exitcrash" flag already available? Nightly build? Git clone? Or is it already on a release?

from nodemon.

remy avatar remy commented on May 5, 2024

--exitcrash is on the latest release - but actually (as someone pointed out) you can do all this in forever:

forever -w start server.js

I'll test this - and if that's the case I'm likely to remove this feature as it's bespoke to forever.

from nodemon.

dnunes avatar dnunes commented on May 5, 2024

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

from nodemon.

exe19890522 avatar exe19890522 commented on May 5, 2024

--exitcrash在最新版本上 - 但实际上(正如有人指出的那样),您可以永远完成所有这些操作:

forever -w start server.js

我会测试这个 - 如果是这种情况,我可能会删除此功能,因为它是永远定制的。

when i use this ,it will show me err ::

node:events:368
throw er; // Unhandled 'error' event
^

Error: listen EADDRINUSE: address already in use :::5000
at Server.setupListenHandle [as _listen2] (node:net:1319:16)
at listenInCluster (node:net:1367:12)
at Server.listen (node:net:1454:7)
at Server.listen (D:\nodejsServer\node_modules\nodejs-websocket\Server.js:119:14)
at WsServer.Startup (file:///D:/nodejsServer/utils/websocket.js:41:17)
at globalStart (file:///D:/nodejsServer/fzServernew.js:103:11)
at file:///D:/nodejsServer/fzServernew.js:119:1
at ModuleJob.run (node:internal/modules/esm/module_job:183:25)
at async Loader.import (node:internal/modules/esm/loader:178:24)
at async Object.loadESM (node:internal/process/esm_loader:68:5)
Emitted 'error' event on Server instance at:
at Server. (D:\nodejsServer\node_modules\nodejs-websocket\Server.js:70:8)
at Server.emit (node:events:390:28)
at emitErrorNT (node:net:1346:8)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'EADDRINUSE',
errno: -4091,
syscall: 'listen',
address: '::',
port: 5000
}
error: Forever detected script exited with code: 1

i don't know why ,5000 is the port of the server's websocket port,i had use 3000 4000 ago,but both will show me this error

from nodemon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.