Skip to main content

Overview

ofetch supports proxy configuration across different JavaScript runtimes, with each runtime having its own approach to proxy handling.
Environment Variables: Bun and Deno respect HTTP_PROXY and HTTPS_PROXY environment variables automatically. Node.js requires setting NODE_USE_ENV_PROXY=1 to enable built-in proxy support.

Environment Variables

All runtimes support standard proxy environment variables:
Node.js requires an additional environment variable:

Node.js Proxy Configuration

Node.js (>= 18) uses undici’s ProxyAgent for proxy support.

Basic Usage

Global Proxy

Set a proxy for all requests:

Per-Instance Proxy

Create a fetch instance with a proxy:

Authenticated Proxy

Proxy from Environment

Bun Proxy Configuration

Bun has native proxy support through the proxy option.

Basic Usage

With Authentication

Per-Instance Proxy

Deno Proxy Configuration

Deno can use environment variables or undici with npm specifiers.

Using Environment Variables

Using Undici (Programmatic)

Complete Example from Source

From examples/proxy.mjs:

Self-Signed Certificates

Allowing self-signed certificates makes fetch vulnerable to MITM attacks. USE AT YOUR OWN RISK!

Node.js (undici Agent)

Combined Proxy + Self-Signed Cert

Dispatcher Type Definition

From src/types.ts:50-54:
The dispatcher option:
  • Only available in Node.js >= 18
  • Uses undici’s Dispatcher interface
  • Supports ProxyAgent, Agent, and other dispatcher types

Runtime Detection Example

TypeScript Interface

Testing Proxy Connection