I have the following problem, once I have to program in nodejs when executing the nodejs application from the console (node app.js) there is a busy port (example port:3000).. when closing the app ( Ctrl+ C) .. The port is still busy and when I run nodejs again it throws me an error Error: listen EADDRINUSE
because it says that there is already an application that uses that port.
When closing it does not close correctly and the port remains open, what I do is look for the app id and kill the port with the command kill
but that takes too many hours when performing a deploy
Is there another way to (safely) close an app in nodejs?
Maybe you press
ctrl + z
. Check well and use this to clean up old node.In your code you can use something like:
Check out the node documentation to see all the signals and events it can handle
process
.