Gathering detailed insights and metrics for proxy-from-env
Gathering detailed insights and metrics for proxy-from-env
Gathering detailed insights and metrics for proxy-from-env
Gathering detailed insights and metrics for proxy-from-env
@types/proxy-from-env
TypeScript definitions for proxy-from-env
@rettgerst/env-proxy
uses _proxies_ to simplify reading from process.env in node.
aws-iam-proxy
A proxy that signs the requests passing through with iam credentials. These credentials could come from an instance profile or ENV vars.
@bugcrowd/aws-iam-proxy
A proxy that signs the requests passing through with iam credentials. These credentials could come from an instance profile or ENV vars.
A Node.js library to get the proxy URL for a given URL based on standard environment variables (http_proxy, no_proxy, ...).
npm install proxy-from-env
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
58 Stars
26 Commits
24 Forks
3 Watchers
3 Branches
3 Contributors
Updated on Jul 09, 2025
Latest Version
1.1.0
Package Id
proxy-from-env@1.1.0
Size
7.59 kB
NPM Version
6.13.6
Node Version
13.7.0
Published on
Mar 04, 2020
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
proxy-from-env
is a Node.js package that exports a function (getProxyForUrl
)
that takes an input URL (a string or
url.parse
's
return value) and returns the desired proxy URL (also a string) based on
standard proxy environment variables. If no proxy is set, an empty string is
returned.
It is your responsibility to actually proxy the request using the given URL.
Installation:
1npm install proxy-from-env
This example shows how the data for a URL can be fetched via the
http
module, in a proxy-aware way.
1var http = require('http'); 2var parseUrl = require('url').parse; 3var getProxyForUrl = require('proxy-from-env').getProxyForUrl; 4 5var some_url = 'http://example.com/something'; 6 7// // Example, if there is a proxy server at 10.0.0.1:1234, then setting the 8// // http_proxy environment variable causes the request to go through a proxy. 9// process.env.http_proxy = 'http://10.0.0.1:1234'; 10// 11// // But if the host to be proxied is listed in NO_PROXY, then the request is 12// // not proxied (but a direct request is made). 13// process.env.no_proxy = 'example.com'; 14 15var proxy_url = getProxyForUrl(some_url); // <-- Our magic. 16if (proxy_url) { 17 // Should be proxied through proxy_url. 18 var parsed_some_url = parseUrl(some_url); 19 var parsed_proxy_url = parseUrl(proxy_url); 20 // A HTTP proxy is quite simple. It is similar to a normal request, except the 21 // path is an absolute URL, and the proxied URL's host is put in the header 22 // instead of the server's actual host. 23 httpOptions = { 24 protocol: parsed_proxy_url.protocol, 25 hostname: parsed_proxy_url.hostname, 26 port: parsed_proxy_url.port, 27 path: parsed_some_url.href, 28 headers: { 29 Host: parsed_some_url.host, // = host name + optional port. 30 }, 31 }; 32} else { 33 // Direct request. 34 httpOptions = some_url; 35} 36http.get(httpOptions, function(res) { 37 var responses = []; 38 res.on('data', function(chunk) { responses.push(chunk); }); 39 res.on('end', function() { console.log(responses.join('')); }); 40}); 41
The environment variables can be specified in lowercase or uppercase, with the lowercase name having precedence over the uppercase variant. A variable that is not set has the same meaning as a variable that is set but has no value.
NO_PROXY
is a list of host names (optionally with a port). If the input URL
matches any of the entries in NO_PROXY
, then the input URL should be fetched
by a direct request (i.e. without a proxy).
Matching follows the following rules:
NO_PROXY=*
disables all proxies.NO_PROXY
list.NO_PROXY
does not contain any entries, then proxies are never disabled.NO_PROXY
list. The only exceptions are entries that start
with a dot or with a wildcard; then the proxy is disabled if the host name
ends with the entry.See test.js
for examples of what should match and what does not.
The environment variable used for the proxy depends on the protocol of the URL.
For example, https://example.com
uses the "https" protocol, and therefore the
proxy to be used is HTTPS_PROXY
(NOT HTTP_PROXY
, which is only used for
http:-URLs).
The library is not limited to http(s), other schemes such as
FTP_PROXY
(ftp:),
WSS_PROXY
(wss:),
WS_PROXY
(ws:)
are also supported.
If present, ALL_PROXY
is used as fallback if there is no other match.
The exact way of parsing the environment variables is not codified in any standard. This library is designed to be compatible with formats as expected by existing software. The following resources were used to determine the desired behavior:
cURL:
https://curl.haxx.se/docs/manpage.html#ENVIRONMENT
https://github.com/curl/curl/blob/4af40b3646d3b09f68e419f7ca866ff395d1f897/lib/url.c#L4446-L4514
https://github.com/curl/curl/blob/4af40b3646d3b09f68e419f7ca866ff395d1f897/lib/url.c#L4608-L4638
wget:
https://www.gnu.org/software/wget/manual/wget.html#Proxies
http://git.savannah.gnu.org/cgit/wget.git/tree/src/init.c?id=636a5f9a1c508aa39e35a3a8e9e54520a284d93d#n383
http://git.savannah.gnu.org/cgit/wget.git/tree/src/retr.c?id=93c1517c4071c4288ba5a4b038e7634e4c6b5482#n1278
W3: https://www.w3.org/Daemon/User/Proxies/ProxyClients.html
Python's urllib:
https://github.com/python/cpython/blob/936135bb97fe04223aa30ca6e98eac8f3ed6b349/Lib/urllib/request.py#L755-L782
https://github.com/python/cpython/blob/936135bb97fe04223aa30ca6e98eac8f3ed6b349/Lib/urllib/request.py#L2444-L2479
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 2/26 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More