Use a proxy with Node.js
Complete proxy requests using undici ProxyAgent, environment variables, AbortSignal timeouts, and security logs.
Maintained by the ZZHTTP engineering teamUpdated September 20, 2026
Node.js example using caller project locked undici Dependency. The account is closed. us.zzhttp.com:7878 Username and password are read from the controlled environment.
Node.js
import { ProxyAgent, fetch } from 'undici';
const username = process.env.PROXY_USERNAME;
const password = process.env.PROXY_PASSWORD;
if (!username || !password) throw new Error('Missing proxy credentials');
const proxyUrl = new URL('http://us.zzhttp.com:7878');
proxyUrl.username = username;
proxyUrl.password = password;
const dispatcher = new ProxyAgent(proxyUrl.toString());
try {
const response = await fetch('https://ipinfo.io/json', {
dispatcher,
signal: AbortSignal.timeout(30_000),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.json());
} finally {
await dispatcher.close();
}
Configuration
- Read the full proxy username and sub-username and password from the controlled environment variable, and do not output the spelled proxy URL to the console.
Request
- Will.
ProxyAgentAs a fetch dispatcher.
- Will.
- Use
AbortSignal.timeoutSet the overall deadline.
Resource release
- After the example is finished, close the agent.
- Production connection pools are reused as agents and deprecated when configuration changes.
Error handling
- Distinguish between timeouts, proxy authentication, and target status.
- The log records only the task ID and status.
Did this answer your question?
Feedback is used only to improve the public documentation and does not submit accounts or request information.