Christian Berg Christian Berg - 2 years ago 117
Node.js Question

How can I use an http proxy with node.js http.Client?

I want to make an outgoing HTTP call from node.js, using the standard

. But I cannot reach the remote server directly from my network and need to go through a proxy.

How do I tell node.js to use the proxy?

Answer Source

Tim Macfarlane's answer was close with regards to using a HTTP proxy.

Using a HTTP proxy (for non secure requests) is very simple. You connect to the proxy and make the request normally except that the path part includes the full url and the host header is set to the host you want to connect to.
Tim was very close with his answer but he missed setting the host header properly.

var http = require("http");

var options = {
  host: "proxy",
  port: 8080,
  path: "",
  headers: {
    Host: ""
http.get(options, function(res) {

For the record his answer does work with but that's because their server doesn't care the host header is incorrect.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download