{"id":27261,"library":"proxy-http-agent","title":"ProxyHttpAgent","description":"ProxyHttpAgent (v1.0.1) is a factory for creating HTTP proxy agents supporting https→(http, https) and http→(http, https) tunneling, built on top of the node-tunnel module. It allows you to easily use proxies with http/https modules or node-fetch, with flexible proxy configuration via URL or object. Published as TypeScript-first with built-in type definitions, it exports `getProxyHttpAgent` along with `HttpsAgent` and `HttpAgent` types. Released in 2025, it is currently at stable v1. It differentiates by offering a simple API for creating agents that support both secure and insecure proxy connections with minimal boilerplate.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/Glitnirian/ProxyHttpAgent","tags":["javascript","proxy","agent","http","https","https-agent","node","node-tunnel","typescript"],"install":[{"cmd":"npm install proxy-http-agent","lang":"bash","label":"npm"},{"cmd":"yarn add proxy-http-agent","lang":"bash","label":"yarn"},{"cmd":"pnpm add proxy-http-agent","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency for creating tunnel agents","package":"tunnel","optional":false}],"imports":[{"note":"ESM import is preferred; the package provides TypeScript types.","wrong":"const getProxyHttpAgent = require('proxy-http-agent')","symbol":"getProxyHttpAgent","correct":"import { getProxyHttpAgent } from 'proxy-http-agent'"},{"note":"TypeScript type for the returned https.Agent instance.","wrong":"","symbol":"HttpsAgent","correct":"import { HttpsAgent } from 'proxy-http-agent'"},{"note":"TypeScript type for the returned http.Agent instance.","wrong":"","symbol":"HttpAgent","correct":"import { HttpAgent } from 'proxy-http-agent'"}],"quickstart":{"code":"import { getProxyHttpAgent } from 'proxy-http-agent';\nimport https from 'https';\n\nconst proxyUrl = process.env.HTTP_PROXY ?? 'http://localhost:3128';\nconst agent = getProxyHttpAgent({\n  proxy: proxyUrl,\n  rejectUnauthorized: false\n});\n\nconst options = {\n  hostname: 'example.com',\n  port: 443,\n  path: '/',\n  agent\n};\n\nhttps.get(options, (res) => {\n  let data = '';\n  res.on('data', chunk => data += chunk);\n  res.on('end', () => console.log(data));\n}).on('error', (err) => console.error(err));","lang":"typescript","description":"Creating a proxy agent with proxy URL from environment and using it with https.get."},"warnings":[{"fix":"Use `opts.agent = agent` after parsing URL, and delete any existing `port` to avoid conflicts.","message":"Options object may override agent settings; ensure `agent` is set correctly.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Double-check package name in package.json.","message":"The npm package name 'proxy-http-agent' may be confused with other similarly named packages. Always verify the correct package.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Always include the protocol in the proxy URL, e.g., 'http://proxy.example.com:8080'.","message":"When using string proxy URL, ensure protocol is specified (http:// or https://).","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Check proxy URL and network connectivity.","cause":"Proxy hostname not resolvable or network issue.","error":"Error: getaddrinfo ENOTFOUND proxy.example.com"},{"fix":"Use `import { getProxyHttpAgent } from 'proxy-http-agent'` instead of `import getProxyHttpAgent from 'proxy-http-agent'`.","cause":"Incorrect import: importing `getProxyHttpAgent` as a function when not imported correctly.","error":"TypeError: agent is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}