title: Getting host name of client url in node.js
body: <p>I am sending data from JavaScript client to node.js server using <code>XMLHttpRequest</code> ajax. Now on server side I need to know the host of URL of the page the JavaScript calling XMLHttpRequest is embedded in. </p>
  
  <p>Server side:</p>
  
  <pre><code>req.on('data', function(data) {
    var d = JSON.parse(data);
    if (d.Type == "abc") {
      var host = req.headers.Host;
      var reply = {
        "hostname": host
      };
      console.log("hostname :" + host);
      response.end(JSON.Stringify(reply));
    }
  });
  </code></pre>
  
  <p>Expected result on console:
         hostname: hostname</p>
  
  <p>Actual result on console:
          hostname: undefined</p>