1

I'm trying to debug my exit/stop events of my node JS server and I read the following threads:

Close event

and

Process events

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.

Community
  • 1
  • 1
TBE
  • 1,002
  • 1
  • 11
  • 32

1 Answers1

1

I ran in to the same issue today using the same bit of code you are. This has to do with the way Node.js processes these events. The debugger services are no longer being serviced via the main event loop, therefor the debugger can't issue it's own event to let the ide know to "break" (and hence no ide interaction).

  • Also, I'm pretty sure this is the line of code that is causing the breaks to be bypassed: https://github.com/nodejs/node/blob/master/lib/_debugger.js#L846 – T.C. Ferguson May 12 '16 at 21:43