proxy-from-env
Resolves the correct proxy URL for a request by reading standard *_PROXY and NO_PROXY environment variables
Repository Health
Technical Analysis
proxy-from-env is a small, focused Node.js utility that answers one question correctly: given a target URL, what proxy (if any) should handle the request, based on the standard HTTP_PROXY/HTTPS_PROXY/*_PROXY, ALL_PROXY, and NO_PROXY environment variables? It implements the de-facto conventions established by tools like curl and wget - protocol-specific proxy variables, NO_PROXY host/port matching with wildcard and dot-prefix rules, and ALL_PROXY as a fallback - so applications don’t have to reimplement this logic themselves.
The library exports a single function, getProxyForUrl, and deliberately does nothing else: it does not perform the proxying itself, leaving that to the caller (commonly paired with packages like https-proxy-agent or proxy-agent). This narrow scope has made it a foundational, widely-depended-upon piece of the Node.js HTTP tooling ecosystem.
What You Get
- A single
getProxyForUrl(url)function accepting a string,URLinstance, or legacyurl.parse()-shaped object - Protocol-aware proxy resolution -
HTTPS_PROXYfor https: URLs,FTP_PROXYfor ftp:,WS_PROXY/WSS_PROXYfor WebSocket URLs, etc. NO_PROXYsupport with exact host matches,*to disable all proxying, dot-prefix/wildcard suffix matching, and optional port matchingALL_PROXYfallback when no protocol-specific variable is set- Both ESM (
index.js) and CommonJS (index.cjs) entry points via packageexports
Common Use Cases
- Adding standard corporate-proxy support to a custom HTTP client without reimplementing environment-variable parsing
- Building a proxy-aware
http.Agent(ashttps-proxy-agent/proxy-agentdo) that decides per-request whether to route through a proxy - Respecting
NO_PROXYexclusion rules so internal/intranet hosts bypass a configured proxy while external requests use it - Ensuring consistent proxy behavior across a Node.js tool by matching the conventions used by curl, wget, and Python’s urllib
Under The Hood
Architecture - The entire implementation lives in a single ~100-line index.js: getProxyForUrl parses the input into a URL (via a small parseUrl helper wrapping the WHATWG URL constructor), extracts protocol/hostname/port, strips brackets/ports consistently for IPv6 hosts, calls a private shouldProxy(hostname, port) to evaluate NO_PROXY rules, and finally reads the appropriate *_proxy/all_proxy environment variable via a getEnv helper that checks both lowercase and uppercase variants (lowercase wins). Tech Stack - Zero-dependency, pure JavaScript (100% JS) targeting Node.js 10+, dual-published as ESM (index.js) and CommonJS (index.cjs), linted with ESLint’s flat config (eslint.config.mjs). Code Quality - test.js is nearly 5x the size of the implementation itself (465 vs 103 lines) and is run via Node’s built-in node --test runner with coverage reporting support, indicating thorough behavioral coverage of the NO_PROXY matching rules, IPv6 handling, and case-insensitive environment variable resolution; a separate test-require.cjs specifically verifies the CommonJS entry point still works. API Design - A single exported function with no configuration object, options, or classes to learn - callers pass a URL and get back a proxy URL string or empty string, mirroring exactly what curl/wget users already expect from proxy environment variables.
Used by 7 apps in this directory
FastGPT
AI Agents · AI Development
Build, debug, and deploy knowledge-based AI agents with a visual workflow editor, RAG retrieval, and support for any OpenAI-compatible LLM.
Kibana
Analytics · Monitoring
Your open source window into the Elastic Stack — query, visualize, and act on data stored in Elasticsearch with real-time dashboards, AI-assisted search, and automated alerting.
n8n
Automation · No Code Platforms
Code when you need it, UI when you don't — the workflow automation platform built for technical teams who refuse to choose.
nao
AI Development · Analytics
Build and deploy an open-source analytics agent that understands your data warehouse and answers business questions in plain English.
Outline
Knowledge Management · Collaboration
A fast, real-time collaborative knowledge base for growing teams built on React, Node.js, and ProseMirror.
Promptfoo
AI Development
An open-source CLI and library for evaluating and red-teaming LLM applications — replace trial-and-error prompt engineering with systematic evals, vulnerability scanning, and CI/CD integration.
Rocket.Chat
Team Chat
The secure, self-hosted team communications platform for organizations that cannot compromise on data sovereignty.