Assuming Node.js v0.10.22 and Express v3. I've been trying to solve a simple problem: when something goes wrong, I'd like to at least display a 500 page and exit the server (since apparently that's the best thing to do - so it can be restarted later).
I can figure it out as far as my own callbacks - I can return an err
response and exit gracefully. What I can't figure out are the scenarios below. Everything I read about is either unstable (http://nodejs.org/api/domain.html) or there's many ways of doing things (domains, uncaughtException, middleware err param).
So, when using Node.js + Express framework: what is the best way for me to display a 500 page and exit cleanly when encountering these scenarios?
a) sdfg(); /* non-existant function */
b) sdfg /* syntax error */
c) throw new Error("can't connect to redis"); /* 3rd party throws an error */
Is there a way at all? How do people do it in production? P.S: Yes, I've seen this page: Error handling principles for Node.js + Express.js applications?