NodeJS request -- how to disable automatic proxy from environment
Asked Answered
N

1

6

I am using the request npm module for making http requests in my program. The default behavior of request seems to be that it will try to use proxy server, when one is defined in environment.

I am testing this in a shared unix server used by multiple developers, who keep changing proxy settings. Further more, I do not need proxy, because I just connect other web services within the lan directly.

So, is there a way to tell the 'request' not to use the proxy option, even though if it is set in environment?

Nose answered 15/5, 2016 at 6:14 Comment(3)
you may start the program like this PROXY_VAR='' node script.js which will apply this env var value to that process. Otherwise, you can try to re define env values within the node process like this process.env['WHATEVER']='';. To call before loading request module.Oldline
request is also aware of the NO_PROXY/no_proxy environment variables or you need to avoid using env variables?Cuddy
so it's NO_PROXY="*" node script.jsCuddy
K
6

Credit goes to @mh-cbon in the comments. Codifying here to complete the answer.

Either blank out the configured proxies prior to starting nodejs

HTTPS_PROXY="" node script.js

Or use NO_PROXY, to disable proxies for specified patterns (or all)

NO_PROXY="*" node script.js

Alternatively within your node js script, do the above before loading and using of request module.

// Disable proxy from being used by request module
process.env["NO_PROXY"]="";

// Then go on as per normal
const request = require("request")
... do stuff ..
Keane answered 10/7, 2019 at 14:50 Comment(1)
In my case for inline approach, adding hostname or asterisk (*) as value instead of just double quotes works. Example: process.env["NO_PROXY"]="*";Pyrrhuloxia

© 2022 - 2024 — McMap. All rights reserved.