title: Node.js handle ENOTFOUND error for http request on invalid host
body: <p>I a have a very simple http request function followed by a couple of sample function calls:</p>
  
  <pre><code>var http = require('http');
  
  
  function makeHttpRequest(host, path){
      var options = {
          host: host,
          path: path
      };
  
      callback = function(response) {
          var str = '';
          //another chunk of data has been recieved, so append it to `str`, i don't use this at all
          response.on('data', function (chunk) {
              str += chunk;
          });
  
          //the whole response has been recieved, do callback
          response.on('end', function () {
              console.log('success');
          });
          response.on('error', function (e) {
              console.log('how do i get this function to execute?');
          });
      }
  
      http.request(options, callback).end();
  }
  
  makeHttpRequest('ec2-1-2-3-4.compute-1.amazonaws.com','thepage.html')
  //makeHttpRequest('google.com','/')//sanity check, this one works fine
  </code></pre>
  
  <p>Running this, I get:</p>
  
  <pre><code>events.js:72
          throw er; // Unhandled 'error' event
                ^
  Error: getaddrinfo ENOTFOUND
      at errnoException (dns.js:37:11)
      at Object.onanswer [as oncomplete] (dns.js:124:16)
  </code></pre>
  
  <p>I want to handle this in the code, not have my application crash.  How can I change my http request to handle this better?  I'm dealing with spot instances on aws ec2 that may come and go, and that is crashing my application here. If that host doesn't exist, I want to re-do that request on another (alive) host.</p>