Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS request -- how to disable automatic proxy from environment

Tags:

node.js

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?

like image 228
Mopparthy Ravindranath Avatar asked May 15 '16 06:05

Mopparthy Ravindranath


1 Answers

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 ..
like image 105
PicoCreator Avatar answered Nov 20 '22 08:11

PicoCreator