PAC Proxy Agent

9.0.1 · active · verified Tue Apr 21

`pac-proxy-agent` is a Node.js module that provides an `http.Agent` implementation for resolving proxy settings using a Proxy Auto-Configuration (PAC) file. It is part of the actively maintained `proxy-agents` monorepo by TooTallNate and is currently at version `9.0.1`. This agent seamlessly integrates with Node.js's native `http` and `https` modules, automatically determining whether to use a direct connection, an HTTP proxy, an HTTPS proxy, or a SOCKS proxy based on the PAC file's logic for a given target URL. Releases typically follow the monorepo's cadence, often aligning major version bumps with Node.js LTS updates, such as the recent shift to Node.js 20. Its key differentiator is its robust and secure PAC file interpretation, leveraging `quickjs-wasi` for isolated PAC script execution.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates initializing `PacProxyAgent` with a PAC file URL and using it with Node.js's built-in `http.get`.

import * as http from 'http';
import { PacProxyAgent } from 'pac-proxy-agent';

const pacFileUrl = process.env.PAC_FILE_URL ?? 'pac+https://cloudup.com/ceGH2yZ0Bjp+';
const targetUrl = process.env.TARGET_URL ?? 'http://nodejs.org/api/';

const agent = new PacProxyAgent(pacFileUrl);

console.log(`Attempting to fetch ${targetUrl} using PAC file from ${pacFileUrl}`);

http.get(targetUrl, { agent }, (res) => {
  console.log(`Successfully connected! Status: ${res.statusCode}`);
  console.log('Response Headers:', res.headers);
  res.pipe(process.stdout);
}).on('error', (err) => {
  console.error('Error fetching URL:', err.message);
  process.exit(1);
});

view raw JSON →