I have the following code to capture a ^C from the terminal and gracefully shutdown my Express app:
process.on('SIGINT', () => {
console.log('SIGINT received ...');
console.log('Shutting down the server');
server.close(() => {
console.log('Server has been shutdown');
console.log('Exiting process ...');
process.exit(0);
});
});
However if I start my node instance with --inspect
, then the above code fails to stop the inspector and the Chrome debugger. When I restart my application, I get the following error:
Starting inspector on 127.0.0.1:9229 failed: address already in use
How do I gracefully stop my app to avoid this error?
Full code available here.