Skip to content

Global HTTP/HTTPS proxy agent configurable using environment variables.

License

Notifications You must be signed in to change notification settings

gajus/global-agent

Repository files navigation

global-agent

Travis build status Coveralls NPM version Canonical Code Style Twitter Follow

Global HTTP/HTTPS proxy configurable using environment variables.

Usage

Setup proxy

To configure HTTP proxy:

  1. Import global-agent/bootstrap.
  2. Export HTTP proxy address as GLOBAL_AGENT_HTTP_PROXY environment variable.

Code:

import 'global-agent/bootstrap';

Bash:

$ export GLOBAL_AGENT_HTTP_PROXY=http:https://127.0.0.1:8080

Alternatively, you can preload module using Node.js --require, -r configuration, e.g.

$ export GLOBAL_AGENT_HTTP_PROXY=http:https://127.0.0.1:8080
$ node -r 'global-agent/bootstrap' your-script.js

Enable logging

global-agent is using roarr logger to log HTTP requests.

Export ROARR_LOG=true environment variable to enable log printing to stdout.

Use roarr-cli program to pretty-print the logs.

Supported libraries

global-agent works with all libraries that internally use http.request.

global-agent has been tested to work with:

FAQ

How does it work?

global-agent works be configuring http.globalAgent and https.globalAgent.

What version of Node.js are supported?

global-agent works with Node.js v12.0.0 and above.

What is the reason global-agent does not use the standard HTTP_PROXY environment variable?

Some libraries (e.g. request) change their behaviour when HTTP_PROXY environment variable is present. Using a namespaced environment variable prevents conflicting library behaviour.

What is the difference from global-tunnel?

global-tunnel (and global-tunnel-ng) are designed to support legacy Node.js versions and rely on monkey-patching http.request, http.get, https.request and https.get methods. global-agent works by configuring http.globalAgent.