Registry / devops / node-pac

node-pac

JSON →
library0.5.1jsnpmunverified

Node.js PAC script parser and executor. Current stable version 0.5.1 (last published ~2018). Low maintenance; last commit years ago. Parses PAC files to determine proxy settings for given URLs. Supports HTTP(S) and local PAC files with automatic caching and refresh. Provides both standard proxy string format and Whistle-compatible format. Minimal dependencies; suitable for basic proxy resolution in Node.js applications.

npm install node-pac
INSTALL
IMPORT
SIG · NODE-PAC
N
node-pac
devopsjavascriptv0.5.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Pac
import Pac from 'node-pac'
const { Pac } = require('node-pac')
CommonJS require gives the constructor directly, not as named export. Default import works in ESM environments if transpiled.
pac.FindProxyForURL
const pac = new Pac(url); pac.FindProxyForURL(urlStr, cb)
Pac.FindProxyForURL(urlStr, cb)
FindProxyForURL is an instance method, not static.
new Pac() / Pac()
const pac = new Pac(options)
const pac = Pac.new(options)
Constructor can be called with or without 'new' — both work.

Create a PAC instance from a remote URL and resolve proxy for a URL using FindProxyForURL callback.

const Pac = require('node-pac'); const pac = new Pac('https://raw.githubusercontent.com/imweb/node-pac/master/test/scripts/normal.pac'); pac.FindProxyForURL('http://example.com', (err, res) => { if (err) console.error(err); else console.log(res); // e.g., PROXY 127.0.0.1:8080 });
Debug
Known issues
gotchaThe library uses callback-based async; no Promise support. Cannot use async/await directly without promisification.
fix
Wrap calls in a Promise: new Promise((resolve, reject) => pac.FindProxyForURL(url, (err, res) => err ? reject(err) : resolve(res)))
affects: >=0.0.0
gotchaMethod names are case-sensitive and inconsistently cased: FindProxyForURL (camelCase with capital F) and findProxyForURL (lowercase f) both exist but one may be undocumented.
fix
Use the documented casing 'FindProxyForURL' for consistency; both work but prefer the documented one.
affects: >=0.0.0
gotchaPAC script caching: default cache time is 30 seconds. If you need fresh script on every call, set cacheTime: 0 or use forceUpdate().
fix
Set cacheTime: 0 in options to disable caching, or call pac.forceUpdate() before each request.
affects: >=0.0.0
gotchaIf the PAC script fetch fails (e.g., timeout, network error), the library silently uses the last cached script. No error is returned to the callback unless forceUpdate() was called.
fix
Use pac.forceUpdate() to ensure errors are propagated, or implement your own error handling around fetch.
affects: >=0.0.0
gotchaThe library has not been updated since 2018. It may not work with newer Node.js versions (tested up to Node 6). Potential compatibility issues with modern JavaScript features or security vulnerabilities.
fix
Consider using alternative PAC libraries that are actively maintained, such as 'pac-proxy-agent' or 'proxy-agent'.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'node-pac'
Package not installed or import path incorrect.
fix
Run 'npm install node-pac' and ensure require path is correct (use 'node-pac' not './node-pac').
TypeError: pac.FindProxyForURL is not a function
FindProxyForURL is an instance method, but called statically or on wrong object.
fix
Ensure you create an instance: const pac = new Pac(options); then call pac.FindProxyForURL(url, cb).
Error: getaddrinfo ENOTFOUND raw.githubusercontent.com
Network issue when fetching remote PAC file (e.g., URL invalid, no internet).
fix
Check the PAC URL is accessible. Use a local PAC file or handle network errors gracefully.
ReferenceError: FindProxyForURL is not defined
Method name is case-sensitive; used lowercase 'findProxyForURL' but function expects exact casing.
fix
Use 'FindProxyForURL' (capital F) as documented. Both exist but prefer documented version.
Upgrade
Version history
0.5.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
node-pac — npm install node-pac · libregistry