> Is there a way to get ALL outbound HTTP requests from node apps to use
> the HTTP_PROXY environment variable? I'm behind a corporate firewall
> and must go through a proxy.
> In my own code, I can successfully get through the proxy by using
> Mikeal's request:
> var request = require('request');
> request = request.defaults({proxy: process.env.HTTP_PROXY });
> request.get({
> url: "http://google.com"}, function(e,r,body) {
> if (body.indexOf('doctype')) {
> console.log("Loaded google.com");
> }
> else {
> console.log("Error loading google.com", e);
> }
> });
> But what about 3rd-party libs installed via NPM? Is there a way to get
> them to recognize the HTTP_PROXY setting? Obviously, I can't hack all
> of them to update request.get with my proxy setting. And some of them
> don't use request. As you can see above, I've even setting a default
> proxy in my app logic. But as I assumed, this doesn't pass through to
> other libs. For instance, I'm trying to get this working with jsdom:
> var request = require('request');
> request = request.defaults({proxy: process.env.HTTP_PROXY });
> var jsdom = require('jsdom');
> jsdom.env("http://nodejs.org/dist/", [
> 'http://code.jquery.com/jquery-1.5.min.js'
> ],
> function(errors, window) {
> console.log("Window: ", window);
> if (errors) {
> console.log("Error: ",errors);
> }
> else {
> console.log("There have been", window.$("a").length, "nodejs
> releases!");
> }
> });
> This results in:
> Window: undefined
> Error occurred { [Error: connect ECONNREFUSED]
> code: 'ECONNREFUSED',
> errno: 'ECONNREFUSED',
> syscall: 'connect' }
> There must be others building Node apps behind a proxy. How do you
> deal with this?
> Thanks!
> Tauren