Use process.on('uncaughtException to show a 500 error page Use process.on('uncaughtException to show a 500 error page express express

Use process.on('uncaughtException to show a 500 error page


I don't think you can from within the uncaughtException do a response since that could happen even when there is no request occurring.

Express itself provides a way to handle errors within routes, like so:

app.error(function(err, req, res, next){    //check error information and respond accordingly});


Per ExpressJS Error Handling, add app.use(function(err, req, res, next){ // your logic }); below your other app.use statements.

Example:

app.use(function(err, req, res, next){  console.log(err.stack);  // additional logic, like emailing OPS staff w/ stack trace});