proxy-chain is a Node.js library that provides a programmable HTTP/SOCKS proxy server with extensive features. It supports SSL/TLS, authentication, upstream proxy chaining, and protocol tunneling, enabling dynamic and custom configurations. Key differentiators include its utility for headless browsers like Puppeteer and Playwright, which struggle with authenticated proxy URLs, by providing a local proxy that handles authentication. The library also offers traffic statistics and custom HTTP response capabilities. Developed by Apify, it's a core component in their web scraping platform and is used by Crawlee. The current stable version is 2.7.1, with minor and patch releases occurring frequently, typically on a monthly basis.
npm install proxy-chainVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up a basic HTTP/HTTPS proxy server that listens on a specified or default port and logs its status. It includes a graceful shutdown handler.
Update your import statements to use named exports: `import { Server } from 'proxy-chain';` for ESM or `const { Server } = require('proxy-chain');` for CommonJS. If importing the module object, access the Server class as a property: `const ProxyChain = require('proxy-chain'); new ProxyChain.Server()`.Upgrade your Node.js runtime environment to version 14 or higher to ensure compatibility. The `engines` field in `package.json` specifies `>=14`.
Always return an object matching the specified signature from your `authenticate` function. Ensure `requestAuthentication` is a boolean and `upstreamProxyUrl` is a string if an upstream proxy is intended.
Ensure your upstream proxies or client configurations use Basic authentication. For more complex schemes, you might need to implement custom logic within the `authenticate` handler or use another proxy layer.
Access the `Server` class from the imported module object using `new ProxyChain.Server()` or destructure it directly with `const { Server } = require('proxy-chain'); new Server()` for CommonJS, or `import { Server } from 'proxy-chain'; new Server()` for ESM.For ESM projects, use `import { Server } from 'proxy-chain';`. For CommonJS projects, use `const { Server } = require('proxy-chain');`. Ensure your project's module system is consistently configured.Validate and ensure that your `upstreamProxyUrl` is a correctly formatted URL. URI-encode username and password components if they contain special characters. Refer to RFC 3986 for URL encoding guidelines.
No dependency data recorded yet.