npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

netbun

v0.2.1

Published

Zero-dependency socks proxy implementation for bun runtimer.

Readme

netbun

CI npm version License: MIT

A high-performance, zero-dependency fetch implementation for Bun with comprehensive proxy support, including SOCKS5, SOCKS4, HTTP, and HTTPS proxies. Features automatic decompression, redirect handling, connection pooling, and more.

This library extends Bun's native capabilities by providing a drop-in replacement for fetch that supports various proxy protocols and advanced networking features not available in the standard implementation.

Table of Contents

Features

  • 🚀 Zero Dependencies: Uses only Bun/Node native modules (net, tls, zlib).
  • 🧦 Comprehensive Proxy Support: SOCKS5, SOCKS4, HTTP, and HTTPS proxies with automatic fallback.
  • 🔒 SOCKS5 & SOCKS4: Full handshake with Username/Password authentication (RFC 1928/1929).
  • 🌐 HTTPS/TLS: Automatic socket upgrade to TLS for secure connections.
  • 📦 Native Fetch API: Drop-in replacement with identical interface to standard fetch.
  • High Performance: Connection pooling, streaming responses, and optimized parsing.
  • 🔄 Decompression: Supports gzip, deflate, brotli, and zstd encodings.
  • ↩️ Redirect Handling: Full support for follow, manual, and error redirect modes.
  • 🔧 Proxy URL Converter: Converts between various non-standard proxy formats.
  • 🌍 IPv6 Support: Full IPv6 address handling in proxy configurations.
  • 🛡️ Security: Proper header preservation, authentication, and connection management.

Installation

bun add netbun

Usage

Import fetch from the library and use the proxy option in the init object. The library supports various proxy protocols and automatically handles connection details.

import { fetch } from 'netbun';

// Use SOCKS5 proxy
const response = await fetch('https://api.example.com', {
  proxy: 'socks5://user:[email protected]:1080'
});

// Use HTTP proxy
const response2 = await fetch('https://api.example.com', {
  proxy: 'http://user:[email protected]:8080'
});

// No proxy - falls back to native fetch
const response3 = await fetch('https://api.example.com');

Examples

Basic GET Request

import { fetch } from 'netbun';

const response = await fetch('https://api.ipify.org?format=json', {
	proxy: 'socks5://myuser:[email protected]:1080',
});

const data = await response.json();
console.log(data);

POST Request with Custom Headers

import { fetch } from 'netbun';

const response = await fetch('https://example.com/api/data', {
	method: 'POST',
	body: JSON.stringify({ key: 'value' }),
	headers: {
		'Content-Type': 'application/json',
		Authorization: 'Bearer token',
	},
	proxy: 'socks5://user:[email protected]:1080',
});

Redirect Handling

import { fetch } from 'netbun';

// Follow redirects (default)
const response = await fetch('https://httpbin.org/redirect/3', {
	proxy: 'socks5://user:[email protected]:1080'
});

// Error on redirect
try {
	await fetch('https://httpbin.org/redirect/1', {
		proxy: 'socks5://user:[email protected]:1080',
		redirect: 'error'
	});
} catch (error) {
	console.log('Redirect blocked:', error.message);
}

Using Different Proxy Types

import { fetch } from 'netbun';

// SOCKS5 proxy
await fetch('https://example.com', { proxy: 'socks5://user:pass@host:1080' });

// SOCKS4 proxy
await fetch('https://example.com', { proxy: 'socks4://host:1080' });

// HTTP proxy
await fetch('https://example.com', { proxy: 'http://user:pass@host:8080' });

// HTTPS proxy
await fetch('https://example.com', { proxy: 'https://user:pass@host:8080' });

Drop-in Replacement

The library falls back to native fetch when no proxy is specified, making it safe to use as a global replacement.

// Uses proxy
await fetch('https://secret-service.com', { proxy: 'socks5://...' });

// Uses standard connection
await fetch('https://google.com');

API

fetch(input: string | URL | Request, init?: RequestInit & { proxy?: string | { url: string; resolveDnsLocally?: boolean } }): Promise<Response>

An enhanced fetch function with comprehensive proxy support and advanced networking features.

  • Parameters:
    • input: The URL, Request object, or string to fetch.
    • init: Optional init object with standard fetch options plus:
      • proxy: Proxy configuration string or object
      • redirect: Redirect handling mode ('follow', 'error', 'manual')
  • Returns: A Promise that resolves to a Response object.
  • Throws: Errors for invalid proxy URLs, connection failures, or redirect errors.

Proxy Support:

  • SOCKS5: socks5://user:pass@host:port
  • SOCKS4: socks4://host:port
  • HTTP: http://user:pass@host:port
  • HTTPS: https://user:pass@host:port

If no proxy is provided, it falls back to the native globalThis.fetch.

convert(proxyUrl: string | string[], skipInvalid?: boolean): string | string[]

Converts proxy URL(s) from various non-standard formats to the standard proxy URL format.

  • Parameters:
    • proxyUrl: Single proxy URL string or array of proxy URLs in any supported format.
    • skipInvalid: (Optional) If true and array is passed, skips invalid URLs instead of throwing errors. Default: false.
  • Returns: Standard proxy URL(s) in format protocol://[user:pass@]host:port.
  • Throws: Error if the proxy URL format is invalid (unless skipInvalid is true for arrays).

See Supported Formats for detailed examples.

Configuration

Proxy URL Formats

The library supports various proxy protocols and authentication methods:

SOCKS5

  • No Auth: socks5://127.0.0.1:9050
  • With Auth: socks5://user:[email protected]:1080
  • IPv6: socks5://user:password@[2001:db8::1]:1080

SOCKS4

  • Basic: socks4://proxy.example.com:1080

HTTP/HTTPS

Environment Variables

The library also respects standard proxy environment variables:

  • SOCKS5_PROXY
  • SOCKS_PROXY
  • HTTP_PROXY
  • HTTPS_PROXY

SOCKS4

  • Basic: socks4://proxy.example.com:1080

HTTP/HTTPS

Environment Variables

The library also respects standard proxy environment variables:

  • SOCKS5_PROXY
  • SOCKS_PROXY
  • HTTP_PROXY
  • HTTPS_PROXY

Supported Formats

The convert function supports various non-standard proxy URL formats for maximum compatibility:

  • Standard: protocol://[user:pass@]host:port
  • Colon-separated: protocol://host:port:username:password
  • Inverted: protocol://host:port@user:pass
  • Without protocol: host:port:username:password (defaults to socks5)
  • IPv6: [2001:db8::1]:1080 or socks5://[2001:db8::1]:1080

Supported protocols: socks5, socks4, http, https

import { convert } from 'netbun';

// Convert various formats
convert('proxy.example.com:1080:user:pass')
// => 'socks5://user:[email protected]:1080'

convert('socks5://proxy.com:1080@admin:secret')
// => 'socks5://admin:[email protected]:1080'

convert('[2001:db8::1]:1080:user:pass')
// => 'socks5://user:pass@[2001:db8::1]:1080'

License

MIT