For an Express-side HTTPS call using the environment's proxy policy:

import https from 'node:https';
import { ProxyAgent } from 'proxy-agent';

const agent = new ProxyAgent();
const request = https.get('https://service.example/data', { agent }, response => {
  console.log(response.statusCode);
  response.resume();
});
request.on('error', error => console.error(error.message));

The current ProxyAgent constructor takes an options object. With no override it reads supported environment policy through proxy-from-env and picks the lower-level agent for the URL.

For an application-owned fixed route, replace selection through that options object:

new ProxyAgent({ getProxyForUrl: () => proxyUrl })

A constant callback does not apply the default environment's NO_PROXY decisions. Implement the required direct exceptions in your selector when replacing it.

For a permitted public-service call, the free proxy list supplies candidates for proxyUrl; select a protocol supported by the agent. The returned proxy URL's scheme identifies the intermediary protocol; https.get still names the real service. Retain the agent for its workload and destroy it at shutdown.

The Express listener accepts incoming requests and does not configure this outbound connection. An Undici-based fetch uses another transport input too: Undici’s fetch with a ProxyAgent takes a dispatcher, using a package release compatible with the Node runtime.

Erthyglow kevrennek