Node.js global proxy setting

I was working in a crop network behind a proxy server. In my code I can set the proxy by using the approach mentioned in this thread (How can I use an http proxy with node.js http.Client?).

But the problem is that, most of the 3rd party modules do not have proxy setting and I cannot modify their code to add the proxy. Also my code might be used in a directly connection environment which means I cannot hard-code my proxy setting in code.

I know NPM has a global setting for proxy which is

npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080

But I didn't find any config similar in Node.js.

Does Node.js support global proxy setting so that I don't need to change all codes and switch on and off easily.

I finally created a module to get this question (partially) resolved. Basically this module rewrites http.request function, added the proxy setting then fire. Check my blog post http://blog.shaunxu.me/archive/2013/09/05/semi-global-proxy-setting-for-node.js.aspx

Unfortunately, it seems that proxy information must be set on each call to http.requrest. Node does not include a mechanism for global proxy settings.

The global-tunnel module on NPM appears to handle this, however:

var globalTunnel = require('global-tunnel');

globalTunnel.initialize({
  host: 'proxy.example.com',
  port: 8080
});

After the global settings are establish with a call to initialize, both http.request and the requests library will use the proxy information.

The module can also use the http_proxy environment variable:

process.env.http_proxy = 'http://proxy.example.com:3129';
globalTunnel.initialize();