Can't debug node.js "stop" event and process "exit" event
<p>I'm trying to debug my exit/stop events of my node JS server and 
I read the following threads:</p>

<p><a href="https://stackoverflow.com/questions/18692536/node-js-server-close-event-doesnt-appear-to-fire">Close event</a></p>

<p>and</p>

<p><a href="https://stackoverflow.com/questions/14031763/doing-a-cleanup-action-just-before-node-js-exits">Process events</a></p>

<p>Tried implementing them both but i can't seem to stop on a breakpoint when i click the "Stop" button in my WebStorm IDE.</p>

<p>I have the following code in my bin/www file:</p>

<pre><code>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}));
</code></pre>

<p>But when i stop my debug session non of the above is fired.</p>

<p>I also tried to use <code>server.on('stop',...)</code> with no luck.</p>

<p>I'm suspecting that pressing on the <code>stop</code> 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.</p>

<p>**EDIT: **
I also tries the <code>SIGTERM</code> and <code>SIGKILL</code> events. I'm using iOS.</p>