proxy authentication in node.js with module request

Victor picture Victor · May 10, 2014 · Viewed 54.9k times · Source

I'm trying to use the module request in my node.js app, and I need to configure proxy settings with authentication.

My settings are something like this:

proxy:{
    host:"proxy.foo.com",
    port:8080,
    user:"proxyuser",
    password:"123"
}

How can i set my proxy configuration when i make a request? Could someone give me an example? thanks

Answer

Victor picture Victor · May 25, 2014

Here is an example of how to configure (https://github.com/mikeal/request/issues/894):

//...some stuff to get my proxy config (credentials, host and port)
var proxyUrl = "http://" + user + ":" + password + "@" + host + ":" + port;

var proxiedRequest = request.defaults({'proxy': proxyUrl});

proxiedRequest.get("http://foo.bar", function (err, resp, body) {
  ...
})