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.
Core requests used SOCKS; native fetch ignored the incompatible agent option.
Local Node comparison
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.
| Client | Connection option | SOCKS integration boundary |
|---|---|---|
| node:http / node:https | agent | Use SocksProxyAgent explicitly |
| Native Node fetch | dispatcher | Needs a compatible Undici integration |
| Axios Node adapter | httpAgent / httpsAgent | Review adapter and competing proxy behavior |
| Browser JavaScript | Browser networking stack | Cannot 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.
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 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.
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.
| Request configuration | Rounds | SOCKS observation | Response marker |
|---|---|---|---|
| http.get + socks5h Agent | 3 | ATYP 3 · localhost | 3 PROXY_PATH |
| http.get + socks5 Agent | 3 | ATYP 4 · local IP | 3 PROXY_PATH |
| Native fetch + agent option | 3 | Zero SOCKS connections | 3 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.
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 RoxyBrowserReview the official desktop profile workflow. A Node Agent does not configure an existing browser profile.
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.
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.
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.
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.