https-proxy-agent is an `http.Agent` implementation specifically designed for making HTTPS requests through an HTTP or HTTPS proxy server. It leverages the HTTP `CONNECT` method to establish a TCP tunnel through the proxy to the target destination. This enables secure communication over proxied networks and is also compatible with protocols like WebSockets that utilize the `CONNECT` method for proxy tunneling. The current stable version is 9.0.0, released as part of the `proxy-agents` monorepo, which implies a release cadence tied to updates across the proxy agent family. A key differentiator is its direct focus on the `CONNECT` method for HTTPS and WebSocket tunneling, providing a robust solution for environments requiring explicit proxy configuration. It requires Node.js version 20 or higher.
npm install https-proxy-agentVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to configure and use `HttpsProxyAgent` with Node.js's built-in `https` module to route requests through a specified HTTP(s) proxy server.
Upgrade your Node.js environment to version 20 or newer. If you cannot upgrade, use a previous major version of `https-proxy-agent` (e.g., `^8.0.0`).
Use `import { HttpsProxyAgent } from 'https-proxy-agent';` instead of `const HttpsProxyAgent = require('https-proxy-agent').HttpsProxyAgent;` in your JavaScript/TypeScript files.Ensure the proxy URL is a valid string (e.g., 'http://proxy.example.com:8080' or 'https://secureproxy.com') or a `URL` object. Always include the protocol (http/https).
Convert your project to use ES Modules, or if that's not feasible, ensure your tooling (e.g., Webpack, Rollup) correctly handles ESM modules in a CommonJS context. The recommended fix is to use `import { HttpsProxyAgent } from 'https-proxy-agent';` and ensure your project's `type` is set to `module` in `package.json` or use an `.mjs` extension for your file.Double-check your proxy URL, port, and any required authentication. Verify network connectivity to the proxy server. The proxy might also be blocking the target URL.