The port is occupied when pressing CTRL + C from the linux terminal with Nodejs applications

3

I have the following problem, since 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 (< kbd> Ctrl + C ) ... the port is still busy and when I rerun the nodejs it throws me%% error% because it says that there is already an application that uses that port.

When closing does not close correctly and the port is open, what I do is find the app's id and kill the port with the Error: listen EADDRINUSE command but that takes too many hours when deploying a deploy

Is there another way to close (safely) an app in nodejs?

    
asked by Luis Alberto Aguilera Clarke 02.03.2016 в 16:56
source

1 answer

2

Maybe you press ctrl + z . Check well and use this to clean up old node processes.

ps aux | awk '/node/{print$2}' | xargs kill -9

In your code you can use something like:

process.on('SIGHUP', () => {
  console.log('SIGHUP');
});

process.kill(process.pid,'SIGHUP')

Review the node documentation to see all the signals and events that process can handle.

    
answered by 03.03.2016 / 03:01
source