hpagent is a Node.js library providing HttpProxyAgent and HttpsProxyAgent classes designed to facilitate HTTP and HTTPS requests through proxy servers while leveraging connection keep-alive mechanisms. Currently at version 1.2.0, it maintains an active development status with periodic releases introducing features and bug fixes, such as strict TypeScript support and improved proxy handling. A key differentiator is its ability to serve as a drop-in replacement for Node.js's native `http` and `https` agents, offering robust proxy configuration options, including basic authentication via URL or custom headers, and the ability to pass specific options for the proxy CONNECT request. The library explicitly demonstrates compatibility with popular userland HTTP clients like `got`, `needle`, `node-fetch`, and `simple-get`, and ships with TypeScript type definitions, making it suitable for modern Node.js applications (Node.js >=14 is required since v1.0.0).
npm install hpagentVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to create and use an HttpProxyAgent with basic authentication for an HTTP request via Node.js's built-in http module. This code uses environment variables for sensitive data and target host/port, making it runnable and adaptable.
Upgrade your Node.js runtime to version 14 or higher.
Consult the package documentation table to determine the appropriate agent based on your proxy and target server types.
Ensure the proxy URL contains correct credentials or provide them in `proxyConnectOptions.headers`. Remember that username/password are not URL-encoded by hpagent itself since v1.0.0.
Supply the proxy's certificate chain in `proxyConnectOptions.ca` (e.g., `ca: [fs.readFileSync('custom-proxy-cert.pem')]`).Add the proxy's certificate(s) to the `proxyConnectOptions.ca` array, or configure Node.js to trust the certificate globally (less secure).
Ensure the `proxy` option is a valid URL string, including the protocol (e.g., `http://`, `https://`), host, and port, like `http://localhost:8080`.
No dependency data recorded yet.