global-tunnel-ng is a utility that globally configures Node.js's built-in `http` and `https` agents to route all outgoing network traffic through an upstream HTTP proxy. It works transparently for modules that utilize Node's default `http.request()` method and popular libraries like `request`. The current stable version is 2.7.1, published in November 2018. The package focuses on transparent global proxying, allowing developers to set a proxy once for an entire application without modifying individual HTTP client calls. It supports both `CONNECT` tunneling for HTTPS (and optionally HTTP) and absolute-URI request methods, accommodating various proxy configurations. Its primary differentiator is its low-level global interception of Node.js's native networking stack. For modern Node.js versions (v10+), `global-agent` is often recommended as a more actively maintained alternative.
npm install global-tunnel-ngVerified import paths — ran on the pinned version, not inferred.
This quickstart initializes a global HTTP/HTTPS proxy using `global-tunnel-ng` and demonstrates how a standard Node.js `http.get` request automatically routes through it. It also shows how to tear down the proxy.
For Node.js v11.6.0+, migrate to `global-agent` (e.g., `import 'global-agent/bootstrap';` and set `GLOBAL_AGENT_HTTP_PROXY` environment variable) or use a library-specific proxy configuration.
Consult your proxy documentation. Use `connect: 'neither'` for proxies expecting absolute URIs for all requests, or `connect: 'both'` if the proxy expects `CONNECT` for both HTTP and HTTPS requests. The default `connect: 'https'` is suitable for many standard HTTP proxies.
Ensure `global-tunnel-ng` is initialized early in your application. If other modules explicitly define an `agent` option in their `http.request` calls, they will bypass `global-tunnel-ng`'s configuration. Consider using library-specific proxy settings or an alternative like `global-agent` which offers more explicit control and compatibility strategies.
For new projects or applications running on Node.js v10+, consider migrating to `global-agent`. It offers similar global proxying capabilities with better support for newer Node.js features and environment variable configuration.
Verify the `host`, `port`, and `proxyAuth` options in `globalTunnel.initialize()`. Check network connectivity to the proxy. Ensure the proxy supports the `CONNECT` method for the requested protocol (HTTP/HTTPS) as configured by the `connect` option.
Change your import statement to `const globalTunnel = require('global-tunnel-ng');` as `global-tunnel-ng` is a CommonJS module.1) Check Node.js version; if >=11.6.0, switch to `global-agent`. 2) Ensure `global-tunnel-ng` is initialized before other modules that might manage agents. Check if affected modules allow configuring an explicit agent to `null` or `undefined` to force use of the global agent. 3) Review and adjust the `connect` option. 4) Double-check `host`, `port`, and `proxyAuth`.