I am sending data from JavaScript client to node.js server using XMLHttpRequest ajax. Now on server side I need to know the host of URL of the page the JavaScript calling XMLHttpRequest is embedded in.
Server side:
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));
}
});
Expected result on console: hostname: hostname
Actual result on console: hostname: undefined