title: Check if domain name exists with node, return boolean false if not, return domain name if it does
body: <p>I'm trying to do a query on domain names (I'll be looping through a whole bunch) seeing if they exist. I'd like for any domain names that don't exist to return a boolean false and any that do to return the domain name itself (so I can save it to a file). At the moment I have:</p>
  
  <pre><code>var http = require('http'),
      options = {method: 'HEAD', host: 'stackoverflow.com', port: 80, path: '/'};
      req = http.request(options, function(r) {
          console.log(JSON.stringify(r.headers));
      });
  req.end();
  </code></pre>
  
  <p>This very basic, but I've been grappling with Python and Java code libraries for most of the night and all I really want is an if statement that checks the validity of a url without having to mess about with the headers, which I'd have to do if I changed the above code.</p>
  
  <p>Essentially I just want:</p>
  
  <pre><code>if(request === successful) {
    return url;
  } else {
    return false;
  }
  </code></pre>
  
  <p>Apologies for the pseudocode. Pointers welcome (yeah, I know there are no pointers for JavaScript ;)).</p>