Node SOCKS5 Proxy: Agents, DNS and fetch

A Node SOCKS5 proxy needs a client integration that actually owns the connection. For core HTTP and HTTPS requests, supply a compatible SOCKS Agent explicitly. Native fetch uses a different interface: passing the same agent option can leave the request direct. Generate a scoped example and inspect the local route comparison before adapting application code.

9Local Node requests
6/6Agent proxy markers
3/3fetch direct markers
0Public or TLS transfers

Core requests used SOCKS; native fetch ignored the incompatible agent option.

Local Node comparison

1. Choose the client interface before the proxy URL

Node's core http and https modules accept an Agent that manages connection creation. The socks-proxy-agent package implements that interface and negotiates a SOCKS connection before sending the application request. HTTPS then establishes destination TLS over that connection. A SOCKS URL alone does not teach an unrelated HTTP client how to use the Agent.

Node clients, connection options, and SOCKS integration boundaries.
ClientConnection optionSOCKS integration boundary
node:http / node:httpsagentUse SocksProxyAgent explicitly
Native Node fetchdispatcherNeeds a compatible Undici integration
Axios Node adapterhttpAgent / httpsAgentReview adapter and competing proxy behavior
Browser JavaScriptBrowser networking stackCannot open an arbitrary SOCKS TCP socket

The examples target Node v24.16.0 and socks-proxy-agent 8.0.5. Version differences matter, including environment-proxy support and dependency requirements. Check node --version and your lockfile. Do not treat HTTP_PROXY, HTTPS_PROXY or ALL_PROXY as a process-wide SOCKS switch. A service, worker and command-line script may each select a different library or environment.

For this Agent, socks5h:// passes a destination hostname to the proxy, while socks5:// performs a local lookup first. The proxy host still needs to be reachable and may require its own resolution. This distinction changes one connection’s destination lookup; it does not route every DNS request on the machine. Compare the curl DNS examples when checking another client.

2. Generate an explicit HTTP or HTTPS request

The generator creates JavaScript only and makes no request from your browser. Choose CommonJS or ESM, the target protocol, destination DNS and an existing SOCKS listener. The destination is fixed to example.com; credentials are not collected. Save the source using the displayed extension so that the module system matches the imports.

Install in your project: npm install socks-proxy-agent@8.0.5 Review and retain the generated lockfile.

Choose request settings and generate code.

Your Node example will appear here.

Install the package as a direct project dependency. The local measurement reused an existing copy bundled with npm and downloaded nothing; that internal location is not a deployment dependency path. The generated imports use the normal package name. Pinning the tested top-level version documents this example, while a lockfile records its resolved dependency tree.

Each example gives the SOCKS connection a ten-second timeout and uses AbortSignal.timeout for a fifteen-second request deadline, including response reading. It collects at most 64 KiB before destroying an oversized response. Request errors, response errors and premature closure are handled, and the Agent is destroyed when the single request finishes. These limits suit a probe, not a streaming download service.

Core requests do not automatically follow redirects. The code treats non-2xx responses as errors, prints a completed response and keeps certificate verification enabled for HTTPS. A redirect therefore requires a separate decision about the next destination. For larger bodies, use a streaming pipeline with backpressure and a deliberate size policy rather than raising every limit without inspection.

This is not native fetch code. A core Agent cannot simply be renamed dispatcher: the underlying methods differ. Choose a supported SOCKS dispatcher implementation or retain the core request client. If adapting Axios, review both Agent options and its proxy handling; this page provides no tested Axios snippet. Do not apply Node socket options to browser Axios.

3. Inspect the Agent and fetch control measurements

Node v24.16.0 ran three rounds for each of three configurations. A loopback SOCKS responder returned PROXY_PATH after negotiating SOCKS and receiving HTTP. A separate local HTTP listener returned DIRECT_PATH. Both received requests for localhost, so the body identified which route handled the request without relying on a public IP service.

Nine local Node requests comparing core Agents and native fetch.
Request configurationRoundsSOCKS observationResponse marker
http.get + socks5h Agent3ATYP 3 · localhost3 PROXY_PATH
http.get + socks5 Agent3ATYP 4 · local IP3 PROXY_PATH
Native fetch + agent option3Zero SOCKS connections3 DIRECT_PATH

The remote-name configuration transmitted localhost as a SOCKS domain address. The local-lookup configuration sent a loopback IP instead. The responder did not resolve or forward either destination; it returned a local HTTP fixture. These observations establish the client's requested address form, not the behavior of an upstream DNS resolver or a public proxy exit.

The fetch comparison intentionally supplied the core Agent in an unsupported option. On this Node build the option was ignored, no SOCKS connection occurred and the direct marker returned. The same destination served as a control, making the silent routing difference visible. This does not claim that every library ignores unknown options or that a correct custom dispatcher would behave the same way.

Download the complete nine-run CSV, inspect versioned raw observations or rerun the measurement script. Set SOCKS_AGENT_PATH to your installed package directory when rerunning elsewhere. The saved table does not refresh automatically. No public relay, upstream DNS, TLS, proxy authentication or Axios request was measured.

4. Diagnose the connection and manage its lifetime

If the target responds but the SOCKS listener sees nothing, inspect the exact client and connection option before debugging credentials. Check whether another library owns the request, whether a bypass applies and whether a wrapper replaced your settings. Native fetch’s ignored Agent option is a concrete example of why receiving HTTP 200 alone does not prove proxy routing.

A connection refusal points toward the listener address or availability. A name-resolution failure requires checking the selected DNS mode. A certificate error requires investigating the destination trust chain; keep rejectUnauthorized enabled and do not set NODE_TLS_REJECT_UNAUTHORIZED=0. SOCKS authentication and destination application authentication are separate stages. Avoid placing secret-bearing proxy URLs in logs, source control or shared error reports.

For a long-lived application, review connection reuse, concurrent limits, cancellation and shutdown. Do not destroy a shared Agent after each request while other work still uses it. Terminal environment changes may not reach an already running service; the Linux process-scope guide explains that boundary. Verify any required exit identity through the application's actual route.

References: Node HTTP documentation, Node fetch documentation and SOCKS Agent source. These describe separate interfaces; use the installed version when checking compatibility.

Configure browser profiles separately from Node requests.

Download RoxyBrowser

Review the official desktop profile workflow. A Node Agent does not configure an existing browser profile.

Frequently Asked Questions

Can I pass SocksProxyAgent as agent to native fetch?

Native Node fetch uses the Undici dispatcher interface, not the core HTTP Agent interface. Passing an agent option does not configure its SOCKS route. In this local Node version, that option was ignored and the request reached the direct listener. Use a compatible client or a deliberately implemented SOCKS dispatcher.

Does ALL_PROXY make every Node request use SOCKS5?

No universal behavior should be assumed. Environment proxy support depends on the Node version, flags and HTTP library, and supported proxy protocols differ. The generated example supplies an explicit SocksProxyAgent to a core HTTP or HTTPS request rather than relying on environment variables.

Where does socks5h resolve the destination name?

In socks-proxy-agent 8.0.5, socks5h sends the destination name to the SOCKS server; socks5 performs a local lookup first. Resolution of a proxy hostname remains separate. The local experiment observed the requested address type, without measuring an upstream DNS service.

Can I use the same Agent with Axios?

Axios in Node can use core-style httpAgent and httpsAgent options, but its own proxy handling also needs attention. Review the adapter and disable competing proxy configuration where appropriate. Browser Axios does not expose the same socket controls. Axios was not exercised in this dataset.