{"library":"proxy-chain","title":"Node.js Programmable HTTP Proxy","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install proxy-chain"],"cli":null},"imports":["import { Server } from 'proxy-chain';\n// OR (CommonJS)\nconst { Server } = require('proxy-chain');","import { anonymizeProxy } from 'proxy-chain';\n// OR (CommonJS)\nconst { anonymizeProxy } = require('proxy-chain');","import { purgeClosedConnections } from 'proxy-chain';\n// OR (CommonJS)\nconst { purgeClosedConnections } = require('proxy-chain');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { Server } from 'proxy-chain';\n\nconst PORT = process.env.PROXY_PORT ? parseInt(process.env.PROXY_PORT, 10) : 8000;\n\nconst server = new Server({\n    port: PORT,\n    verbose: true,\n    // Optional: add custom authentication logic\n    // An example of a basic authentication handler:\n    // authenticate: ({ username, password }) => {\n    //     return username === 'myuser' && password === 'mypassword';\n    // },\n    // Optional: add upstream proxy chaining logic\n    // upstreamProxyUrl: 'http://user:pass@upstream.example.com:8080',\n});\n\nserver.listen(() => {\n    console.log(`Proxy server is listening on port ${server.port}`);\n    console.log('Use with: `HTTP_PROXY=http://127.0.0.1:' + server.port + ' curl http://example.com`');\n});\n\nprocess.on('SIGINT', async () => {\n    console.log('Shutting down proxy server...');\n    await server.close();\n    console.log('Proxy server closed.');\n    process.exit(0);\n});","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}