Global Agent

4.1.3 · active · verified Wed Apr 22

global-agent is a Node.js library designed to globally configure HTTP/HTTPS proxy settings for outgoing network requests. It intercepts `http.Agent` and `https.Agent` instances to route traffic through a specified proxy server, configurable primarily via environment variables such as `GLOBAL_AGENT_HTTP_PROXY`, `GLOBAL_AGENT_HTTPS_PROXY`, and `GLOBAL_AGENT_NO_PROXY`. The current stable version is 4.1.3, released in March 2026, indicating an active development and maintenance status. The project maintains a steady release cadence, with multiple minor and patch updates in early 2026. Key differentiators include its simple bootstrap mechanism for seamless global integration across applications, support for dynamic runtime re-configuration of proxy settings, and its intentional design to override other explicitly configured HTTP agents. It distinguishes itself by primarily using its own set of environment variables rather than strictly adhering to the standard `HTTP_PROXY` convention for its main bootstrap module.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to enable global HTTP/HTTPS proxying using the side-effect import and environment variables, then makes a sample HTTP request.

import 'global-agent';
import http from 'node:http';

// Simulate setting the environment variable
process.env.GLOBAL_AGENT_HTTP_PROXY = process.env.GLOBAL_AGENT_HTTP_PROXY ?? 'http://127.0.0.1:8080';

console.log(`Global agent will use proxy: ${process.env.GLOBAL_AGENT_HTTP_PROXY}`);

// In a real scenario, you'd run this script with the environment variable set:
// export GLOBAL_AGENT_HTTP_PROXY=http://127.0.0.1:8080 && node your-script.js

// To explicitly bootstrap if not using the side-effect import:
// import { bootstrap } from 'global-agent';
// bootstrap();

const options = {
  hostname: 'example.com',
  port: 80,
  path: '/',
  method: 'GET'
};

const req = http.request(options, (res) => {
  console.log(`STATUS: ${res.statusCode}`);
  console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
  res.setEncoding('utf8');
  let data = '';
  res.on('data', (chunk) => {
    data += chunk;
  });
  res.on('end', () => {
    console.log('Response body length:', data.length);
  });
});

req.on('error', (e) => {
  console.error(`Problem with request: ${e.message}`);
});

req.end();

view raw JSON →