title: Nodejs/express, shutdown gracefully
body: <p>I have an nodejs server running express to server out http calls.  Is there a recommended approach to shutting down the server gracefully if something bad happens?  Should I leave the server running somehow?</p>
  
  <p>I.E. on an uncaught exception the server just stops, I think this will kill over connected clients and not hand them back a response.  </p>
  
  <p>Should I:</p>
  
  <ol>
  <li>Wait for all http connections to complete before I allow the server to die (and then restart it).  </li>
  <li>Or should I try and stop the server from ever dieing?</li>
  </ol>
  
  <p>is this proper?</p>
  
  <pre><code>process.on('exit', function () {
    console.log('About to exit, waiting for remaining connections to complete');
    app.close();
  });
  </code></pre>
  
  <p>In this case an error might have been thrown leaving the server in an undefined state and the server will continue to finish up remaining connections.</p>
  
  <p>Is there any good way to handle errors keep running or should I let the server die and restart?</p>