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

smart-proxy-handler

v1.0.0

Published

Advanced proxy management with rotation, fallback, and intelligent retry for Node.js

Downloads

153

Readme

smart-proxy-handler

Advanced proxy management for Node.js with automatic rotation, intelligent retry, and multi-endpoint fallback.

Installation

npm install smart-proxy-handler

Features

  • Automatic IP rotation (round-robin, random, weighted)
  • Retry based on HTTP status codes with exponential backoff
  • Multi-endpoint fallback
  • Per-proxy health tracking and auto-recovery
  • Periodic health checks with configurable intervals
  • Full TypeScript support

Quick Start

import { ProxyHandler } from "smart-proxy-handler";

const handler = new ProxyHandler({
  proxies: [
    { host: "proxy1.example.com", port: 8080, protocol: "http" },
    { host: "proxy2.example.com", port: 8080, protocol: "http", weight: 2 },
  ],
  rotationStrategy: "weighted",
  retryConfig: {
    maxAttempts: 3,
    delay: 1000,
    backoffFactor: 2,
    retryOnStatusCodes: [429, 500, 502, 503, 504],
  },
  fallbackEndpoints: ["https://backup-api.example.com"],
  healthCheckInterval: 60000,
  onProxyFailure: (proxy, error) => {
    // handle failure
  },
  onProxySuccess: (proxy, latency) => {
    // handle success
  },
});

const response = await handler.request({
  url: "https://api.example.com/data",
  method: "GET",
  headers: { "Accept": "application/json" },
});

console.log(response.status, response.body);
console.log(`Attempts: ${response.attempts}, Latency: ${response.latency}ms`);

API

new ProxyHandler(options)

| Option | Type | Default | Description | |--------|------|---------|-------------| | proxies | ProxyConfig[] | required | List of proxy servers | | rotationStrategy | "round-robin" \| "random" \| "weighted" | "round-robin" | Proxy selection strategy | | retryConfig | Partial<RetryConfig> | see below | Retry configuration | | fallbackEndpoints | string[] | [] | Fallback URLs when all proxies fail | | healthCheckInterval | number | 0 (disabled) | Interval in ms to ping unhealthy proxies | | timeout | number | 30000 | Default request timeout in ms | | onProxyFailure | (proxy, error) => void | - | Callback on proxy failure | | onProxySuccess | (proxy, latency) => void | - | Callback on proxy success |

ProxyConfig

{
  host: string;
  port: number;
  protocol?: "http" | "https" | "socks4" | "socks5";
  auth?: { username: string; password: string };
  weight?: number; // used with "weighted" strategy
}

RetryConfig defaults

{
  maxAttempts: 3,
  delay: 1000,
  backoffFactor: 2,
  retryOnStatusCodes: [429, 500, 502, 503, 504],
  retryOnNetworkErrors: true,
}

handler.request(options)

| Option | Type | Description | |--------|------|-------------| | url | string | Target URL | | method | string | HTTP method (default: GET) | | headers | Record<string, string> | Request headers | | body | string \| Buffer | Request body | | timeout | number | Override default timeout | | skipProxy | boolean | Send request directly without proxy |

Returns a ProxyResponse:

{
  status: number;
  headers: Record<string, string>;
  body: string;
  proxy: ProxyConfig | null;
  latency: number;
  attempts: number;
}

handler.getStats()

Returns an array of ProxyStats for all registered proxies including success/failure counts, average latency, and health status.

handler.destroy()

Stops health check timers and cleans up resources. Always call this when done.

Use Cases

Web Scraping

const handler = new ProxyHandler({
  proxies: residentialProxies,
  rotationStrategy: "random",
  retryConfig: { retryOnStatusCodes: [403, 429, 503] },
});

for (const url of urls) {
  const { body } = await handler.request({ url });
  // parse body
}

Microservices with Fallback

const handler = new ProxyHandler({
  proxies: internalGatewayProxies,
  fallbackEndpoints: [
    "https://region-b.api.internal",
    "https://region-c.api.internal",
  ],
});

API Rate Limit Handling

const handler = new ProxyHandler({
  proxies: ipPool,
  retryConfig: {
    retryOnStatusCodes: [429],
    delay: 2000,
    backoffFactor: 3,
  },
});

Running Tests

npm install
npm test
npm test -- --coverage

License

MIT