Got's agent object is keyed by the destination protocol. A SOCKS connection for an HTTPS URL therefore belongs under https, rather than a new key named socks.

For an existing ESM application using Got and socks-proxy-agent on the HTTP/1 path:

import got from 'got';
import {SocksProxyAgent} from 'socks-proxy-agent';

const agent = new SocksProxyAgent('socks5h://proxy.example:1080');
const body = await got('https://www.example.org/', {
  http2: false,
  agent: {
    http: agent,
    https: agent,
  },
  timeout: {request: 20000},
}).text();

The SOCKS5 proxy list supplies candidates for the example’s no-account proxy URL. The same agent can handle the shown HTTP and HTTPS entries. It establishes the SOCKS connection, then the HTTPS path performs its destination TLS handshake.

In this agent, socks5h leaves destination hostname resolution to the SOCKS proxy. socks5 selects local resolution instead. The proxy's own hostname still needs to be reachable from the Node process.

Got's HTTP/2 agent slot expects a different interface. Do not copy this agent into agent.http2 and assume it provides HTTP/2 proxy support.

Reuse the configured agent for the workload and destroy it when its owner shuts down. Match package versions to the application's Node runtime; this example uses the named SocksProxyAgent export.

Winndannde jowitiiɗe heen