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 http.Client. 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?

10/5/2010 10:32:54 AM

Accepted Answer

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.

5/23/2017 12:18:27 PM

You can use request, I just found it's unbelievably easy to use proxy on node.js, just with one external "proxy" parameter, even more it supports HTTPS through a http proxy.

var request = require('request');

  'method': "GET",
},function (error, response, body) {
  if (!error && response.statusCode == 200) {

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow