NODE.JS / ESM / QUICKSTART
Use a proxy from your Node.js service.
Connect with the native HTTPS client and an explicit proxy agent.
Prerequisites
Use a maintained Node.js release and ES modules (.mjs or type: module). Install https-proxy-agent in your project.
Configuration guide. Purchasing and live connections are not open. Examples require actually provisioned credentials and do not create resources.
Set proxy variables in the server process. Construct the proxy URL with the URL API so credentials are encoded. Pass an explicit agent to the HTTPS request.
npm install https-proxy-agentEnvironment variables
Keep these values in your server process environment. Do not put proxy passwords or keys in browser code, public repositories or screenshots.
- PROXY_HOST
- Assigned proxy hostname, without a protocol prefix
- PROXY_PORT
- The port assigned for the chosen protocol
- PROXY_USERNAME
- Proxy username, separate from your website email
- PROXY_PASSWORD
- Proxy password, separate from the account password or API key
Make a request
The example uses an HTTP proxy to reach an HTTPS target. A SOCKS5 endpoint requires a compatible client and its assigned port; an HTTP proxy URL is not interchangeable with SOCKS5.
import { HttpsProxyAgent } from "https-proxy-agent";
import https from "node:https";
const proxy = new URL(
`http://${process.env.PROXY_HOST}:${process.env.PROXY_PORT}`
);
proxy.username = process.env.PROXY_USERNAME;
proxy.password = process.env.PROXY_PASSWORD;
const request = https.get("https://httpbin.org/ip",
{ agent: new HttpsProxyAgent(proxy) }, response => {
response.pipe(process.stdout);
});
request.setTimeout(30000, () => request.destroy());
request.on("error", () => console.error("Connection failed"));Check the result
Run the example once and inspect the response from the test service. A 30-second socket timeout bounds inactivity; add overall deadlines and status-code handling for production workloads.
Troubleshooting
| Symptom | What to check |
|---|---|
| 407 | Check the proxy username, password and resource status. Avoid repeated automatic retries. |
| Timeout / connection error | Check host, port, firewall and protocol. Diagnose with a single request first. |
| 403 / 429 | Distinguish target responses from proxy authentication. Respect access rules, lower the rate and stop disallowed requests. |
| Unexpected exit | Check whether the plan rotates, the session has expired or the region parameter is supported by the resource. |