1

I am using Express as my Node.js web framework with MongoDB as persistence layer. When I run the server with 'node app.js' command, and occasionally some error occur such as mongoose error or imagemagick error, the hole node process will die and not available from browser. I used Express' error handler but this is still happening. Can someone help?

zhang xuefeng
  • 357
  • 3
  • 11
  • What version of node are you using? I got around this using the clusters package and the process.on('death') message. Look at the example code for clusters on the node.js website – ControlAltDel Apr 16 '12 at 01:45
  • 1
    @zhangxuefeng post this as an answer and then accept it - that way, other people with the same problem will see that there is a solution – Adam Hopkinson Apr 16 '12 at 08:49
  • Duplicate of http://stackoverflow.com/questions/5999373/how-do-i-prevent-node-js-from-crashing-try-catch-doesnt-work – TiansHUo Apr 16 '12 at 09:59

2 Answers2

1
process.on('uncaughtException', function (err) {
  console.error(err);
  console.log("Node NOT Exiting...");
});
TiansHUo
  • 8,309
  • 7
  • 44
  • 57
0
clusters.on('death', function(worker) {
  app.listen(3000);
});
Tim Cooper
  • 151,519
  • 37
  • 317
  • 271
ControlAltDel
  • 32,042
  • 9
  • 48
  • 75