I'm trying to debug my exit/stop events of my node JS server and I read the following threads:
and
Tried implementing them both but i can't seem to stop on a breakpoint when i click the "Stop" button in my WebStorm IDE.
I have the following code in my bin/www file:
var server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
process.stdin.resume();//so the program will not close instantly
function exitHandler(options, err) {
if (options.cleanup) console.log('clean');
if (err) console.log(err.stack);
if (options.exit) process.exit();
}
//do something when app is closing
process.on('exit', exitHandler.bind(null,{cleanup:true}));
//catches ctrl+c event
process.on('SIGINT', exitHandler.bind(null, {exit:true}));
//catches uncaught exceptions
process.on('uncaughtException', exitHandler.bind(null, {exit:true}));
But when i stop my debug session non of the above is fired.
I also tried to use server.on('stop',...)
with no luck.
I'm suspecting that pressing on the stop
button in the IDE to stop the debug session is just not the right way to debug this situation, but since I'm new to node.js maybe I'm doing something wrong with the code.
**EDIT: **
I also tries the SIGTERM
and SIGKILL
events. I'm using iOS.