Getting started with Node.js standard http library

This example assumes your QUOTAGUARD_URL environment variable is set and contains your unique connection string.

To access an HTTP API, you can use the standard HTTP library in Node.js, but you must ensure you correctly set the “Host” header to your target hostname, not the proxy hostname.

var http, options, proxy, url;
http = require("http");

url = require("url");

proxy = url.parse(process.env.QUOTAGUARD_URL);
target = url.parse("http://ip.jsontest.com/");

options = {
  hostname: proxy.hostname,
  port: proxy.port || 80,
  path: target.href,
  headers: {
    "Proxy-Authorization": "Basic " + (new Buffer(proxy.auth).toString("base64")),
    "Host" : target.hostname
  }
};

http.get(options, function(res) {
  res.pipe(process.stdout);
  return console.log("status code", res.statusCode);
});