Can a proxy (like fiddler) be used with Node.js's ClientRequest

chuckj picture chuckj · Jan 2, 2012 · Viewed 24.8k times · Source

Can node.js be setup to recognize a proxy (like Fiddler for example) and route all ClientRequest's through the proxy?

I am using node on Windows and would like to debug the http requests much like I would using Fiddler for JavaScript in the browser.

Just be clear, I am not trying to create a proxy nor proxy requests received by a server. I want to route requests made by http.request() through a proxy. I would like to use Fiddler to inspect both the request and the response as I would if I was performing the request in a browser.

Answer

Naraen picture Naraen · Nov 3, 2014

I find the following to be nifty. The request module reads proxy information from the windows environment variable.

Typing the following in the windows command prompt, will set it for the lifetime of the shell. You just have to run your node app from this shell.

set https_proxy=http://127.0.0.1:8888 
set http_proxy=http://127.0.0.1:8888
set NODE_TLS_REJECT_UNAUTHORIZED=0