Start with the answer: make one process own the proxy environment
proxy agent npm field
Evidence to retain
Runtime check
Confirm Node.js and package engine compatibility
Routing source
Protected proxy environment variables
Bypass rule
Test NO_PROXY separately
Verification record
Process, route label, status, returned address
# How to Use NPM proxy-agent: Environment, Auth, and Checks
The
proxy-agent
package gives Node.js HTTP clients one agent that selects a proxy from standard environment variables. That makes it useful when deployment owns routing, but it also creates a common troubleshooting problem: the effective proxy may not appear anywhere in application code.
Treat the environment as a configuration contract. Define which variable owns the route, which hosts may bypass it, how credentials are injected, and what evidence proves that a request followed the expected path.
Confirm the runtime, then install the package
Check the package version and its
engines
requirement before installation. The current
proxy-agent
8.x line requires Node.js 20 or newer; an older application should not be upgraded blindly just to copy this example. Bind the decision to the version recorded in the lockfile.
node --version
npm view proxy-agent version engines
Frequently Asked Questions
Does `proxy-agent` require the proxy URL in JavaScript?
Not necessarily. Its main workflow selects the proxy from supported environment variables, so the code can create `new ProxyAgent()` without embedding credentials.
Why did a request connect directly?
The hostname may match `NO_PROXY`, the expected variable may be absent from the current process, or the request library may not be using the supplied agent. Check those three points in that order.
Should I create a new agent for every request?
Usually no. Reuse one agent for a related client or batch so the package can reuse underlying agents. Keep unrelated tasks in separately documented processes when their routing policies differ.
Can this configuration guarantee target access?
Install the compatible package in the application that will send the request:
npm install proxy-agent
The current package documentation uses an ES module import:
import { ProxyAgent } from 'proxy-agent';
Check your project's runtime, module system, and lockfile before copying code. A package example that runs in ESM may need an intentional adaptation in a CommonJS project. Do not change the entire module format just to make one snippet compile.
Put routing in the environment, not the source file
The package relies on proxy-related environment variables and the
proxy-from-env
selection rules. Set them in the runtime's protected configuration rather than committing them to
The values above are fictional. For a real deployment, encode reserved characters in credentials and use the endpoint scheme provided in the assignment record.
NO_PROXY
should be narrow: an overly broad suffix can send a verification request directly and create a false conclusion.
Verify one HTTPS request
Create one
ProxyAgent
and pass it to the Node.js request. Reusing the agent allows its internal cache to reuse the appropriate underlying agent for repeated requests.
import https from 'node:https';
import { ProxyAgent } from 'proxy-agent';
const checkUrl = process.env.AUTHORIZED_IP_CHECK_URL;
if (!checkUrl) {
throw new Error('AUTHORIZED_IP_CHECK_URL is required');
}
const agent = new ProxyAgent();
const request = https.get(checkUrl, {
agent,
signal: AbortSignal.timeout(15000),
}, (response) => {
let body = '';
supplies a wall-clock deadline for this one-shot check. By contrast,
request.setTimeout()
sets a socket inactivity timeout after a socket is assigned; it is not a complete request deadline. Use a diagnostic endpoint approved by your team. The returned address must be compared with the expected assignment; status
200
alone does not prove that the correct proxy was selected.
Separate authentication from application errors
When a request fails, preserve the order of events:
No proxy selected: inspect the effective environment and
NO_PROXY
match.
Connection error: verify the assigned host and port from the same runtime.
Authentication error or 407: replace the test credential through the secret store; do not print it.
TLS error: confirm the endpoint scheme and certificate policy rather than disabling verification.
Target HTTP error: record the status separately from proxy negotiation.
Timeout: identify whether the connection or response phase stalled before changing limits.
Do not solve certificate errors with a global setting that disables TLS verification. That turns a visible configuration problem into an invisible security risk.
Confirm what
NO_PROXY
actually bypasses
NO_PROXY
is useful for local services and internal domains, but matching rules can surprise teams. Test at least one host that should use the proxy and one host that should bypass it. Record only sanitized hostnames if the internal names are sensitive.
For repeatable tests, launch a clean process with the exact environment intended for the application. Shell profiles, containers, CI runners, and process managers can each inject different values.
Package support is not product support
The
proxy-agent
package maps several URL schemes to underlying agent implementations. That describes the package, not the availability of a protocol in an IPIPD order. Use only the endpoint scheme and authentication method shown in current product documentation.
IPIPD currently identifies static IP and VPS as separate product categories. VPS is a server product, not a proxy type. This Node.js setup cannot establish whether a static IP is residential or ISP-classified, and it cannot prove speed, future access, account safety, or business outcomes.
A practical handoff record
Before another developer reuses the setup, record:
package name and locked version;
Node.js runtime version;
which environment variable supplied the route;
sanitized proxy host label and port;
NO_PROXY
policy;
diagnostic target, timestamp, status, and observed address;
rollback steps for removing temporary variables.
This record is more useful than a screenshot of a successful response because it explains why the route was selected.
Quick reference: how to verify the proxy-agent environment contract
Not necessarily. Its main workflow selects the proxy from supported environment variables, so the code can create
new ProxyAgent()
without embedding credentials.
Why did a request connect directly?
The hostname may match
NO_PROXY
, the expected variable may be absent from the current process, or the request library may not be using the supplied agent. Check those three points in that order.
Should I create a new agent for every request?
Usually no. Reuse one agent for a related client or batch so the package can reuse underlying agents. Keep unrelated tasks in separately documented processes when their routing policies differ.
Can this configuration guarantee target access?
No. It only controls and observes the request path. Target availability and acceptance remain outside the guarantee of the agent configuration.
No. It only controls and observes the request path. Target availability and acceptance remain outside the guarantee of the agent configuration.