title: Node.js: Will node always wait for setTimeout() to complete before exiting?
body: <p>Consider: </p>
  
  <pre><code>node -e "setTimeout(function() {console.log('abc'); }, 2000);"
  </code></pre>
  
  <p>This will actually wait for the timeout to fire before the program exits. </p>
  
  <p>I am basically wondering if this means that node is intended to wait for all timeouts to complete before quitting.</p>
  
  <p>Here is my situation. My client has a node.js server he's gonna run from Windows with a Shortcut icon. If the node app encounters an exceptional condition, it will typically instantly exit, not leaving enough time to see in the console what the error was, and this is bad. </p>
  
  <p>My approach is to wrap the entire program with a try catch, so now it looks like this: <code>try { (function () { ... })(); } catch (e) { console.log("EXCEPTION CAUGHT:", e); }</code>, but of course this will <em>also</em> cause the program to immediately exit. </p>
  
  <p>So at this point I want to leave about 10 seconds for the user to take a peek or screenshot of the exception before it quits. </p>
  
  <p>I figure I should just use blocking <code>sleep()</code> through the npm module, but I discovered in testing that setting a timeout also seems to work. (i.e. why bother with a module if something builtin works?) I guess the significance of this isn't big, but I'm just curious about whether it is specified somewhere that node will actually wait for all timeouts to complete before quitting, so that I can feel safe doing this. </p>