A SOCKS-capable agent can establish the destination connection for Node's core HTTPS client. With socks-proxy-agent available in the application:

const https = require('node:https');
const { SocksProxyAgent } = require('socks-proxy-agent');

const agent = new SocksProxyAgent('socks5h://proxy.example:1080');
const request = https.get('https://www.example.com/', {
  agent,
  signal: AbortSignal.timeout(15000),
}, (response) => {
  console.log(response.statusCode);
  response.on('error', console.error);
  response.resume();
});
request.on('error', console.error);

Replace the example endpoint with an unauthenticated candidate from the SOCKS5 proxy list for this public HTTPS request. The callback drains the response after printing its status; consume the body there if the application needs it. Reuse the agent for its assigned operations, then destroy it when that client policy is retired and its work has finished.

Choose where the destination name is resolved

In socks-proxy-agent's URL handling, socks5h leaves destination hostname resolution to the proxy path; socks5 resolves locally. This matters when the name is available only on the proxy's network.

The HTTPS URL keeps the website's identity. The agent performs SOCKS negotiation before Node starts TLS to that website.

For a username/password service, put credentials in the proxy URL using URI-component encoding for reserved characters. Keep the complete URL out of logs. Destination Authorization headers belong to the website's account.

This agent works with Node's core HTTP/HTTPS request APIs. Node's fetch uses a dispatcher interface, so configure that client's supported SOCKS integration separately.

Tënë sô zo