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

retry-fetch-pro

v1.0.1

Published

Zero-dependency, type-safe promise retry utility with exponential backoff, jitter, timeout, and abort signal support.

Readme

🔄 retry-fetch-pro

Zero-dependency, type-safe promise retry utility with exponential backoff, jitter, timeout, and abort signal support.

npm version License: MIT Sponsor TypeScript


✨ Features

  • ⚡ Zero Dependencies — Ultra-lightweight, purely native JavaScript / TypeScript.
  • 📈 Exponential Backoff — Configurable base delay, multiplier, and maximum delay ceiling.
  • 🎲 Full Jitter — Randomizes retry delays to prevent thundering-herd issues on downstream servers.
  • ⏱️ Per-Attempt Timeout — Fails fast if any individual attempt hangs (timeoutMs).
  • 🛑 AbortSignal Support — Instantly cancel in-flight or scheduled retries using AbortController.
  • 🔍 Fine-Grained Filtering — Custom shouldRetry predicate to skip non-retryable errors (e.g. 401, 404).
  • 📡 Built-in retryFetch — Drop-in wrapper around native fetch with automatic 5xx server error retry.
  • 📦 Dual ESM & CommonJS — Native compatibility with modern bundlers, Node.js, and browsers.

📥 Installation

npm install retry-fetch-pro

or with Yarn / pnpm:

pnpm add retry-fetch-pro
# or
yarn add retry-fetch-pro

🚀 Quick Start

1. Basic Retry with Default Exponential Backoff

import { retryAsync } from 'retry-fetch-pro';

async function loadData() {
  const result = await retryAsync(async (attempt) => {
    console.log(`Trying attempt #${attempt}...`);
    const res = await fetch('https://api.example.com/items');
    if (!res.ok) throw new Error(`HTTP ${res.status}`);
    return res.json();
  });

  return result;
}

2. Built-in retryFetch

Automatically retries network drops and 5xx server errors:

import { retryFetch } from 'retry-fetch-pro';

const response = await retryFetch('https://api.example.com/data', {
  method: 'GET',
  headers: { 'Content-Type': 'application/json' },
}, {
  retries: 3,
  delayMs: 1000,
});

const data = await response.json();

3. Advanced Configuration

import { retryAsync, TimeoutError, AbortError } from 'retry-fetch-pro';

const controller = new AbortController();

try {
  const data = await retryAsync(
    async (attempt) => {
      return await makePaymentApiCall();
    },
    {
      retries: 4,                  // Max 4 retry attempts
      delayMs: 500,                // Start with 500ms delay
      maxDelayMs: 10000,           // Maximum delay capped at 10s
      backoffFactor: 2,            // 500ms -> 1000ms -> 2000ms -> 4000ms
      jitter: true,                // Add random jitter to avoid spike traffic
      timeoutMs: 3000,             // Fail single attempt if > 3s
      signal: controller.signal,   // Cancel anytime via controller.abort()

      // Skip retry for client error 400, 401, 403, 404
      shouldRetry: (error, attempt) => {
        if (error instanceof Error && error.message.includes('404')) {
          return false; // Do not retry
        }
        return true;
      },

      // Hook invoked before each sleep/retry
      onRetry: (attempt, error, nextDelayMs) => {
        console.warn(`Attempt ${attempt} failed with: ${(error as Error).message}. Retrying in ${nextDelayMs}ms...`);
      },
    }
  );
} catch (err) {
  if (err instanceof TimeoutError) {
    console.error('Request timed out!');
  } else if (err instanceof AbortError) {
    console.warn('Request was cancelled by user');
  } else {
    console.error('All retries failed:', err);
  }
}

⚙️ Options Reference

| Option | Type | Default | Description | |---|---|---|---| | retries | number | 3 | Maximum number of retry attempts. | | delayMs | number | 500 | Initial delay in milliseconds before the first retry. | | maxDelayMs | number | 30000 | Ceiling limit for exponential backoff delay. | | backoffFactor | number | 2 | Multiplier applied to delay after each retry. | | jitter | boolean | true | When true, randomizes backoff to avoid synchronized retry storms. | | timeoutMs | number | undefined | Per-attempt timeout in milliseconds. Throws TimeoutError. | | signal | AbortSignal | undefined | Optional signal to cancel all pending retries. | | shouldRetry | (err, attempt) => boolean \| Promise<boolean> | () => true | Predicate function to allow or block retries. | | onRetry | (attempt, err, delay) => void | undefined | Callback invoked before each wait cycle. |


🛠 Development & Testing

# Install dependencies
npm install

# Run unit tests
npm test

# Build dual ESM/CJS bundles + .d.ts types
npm run build

🚢 Publishing to NPM

  1. Login to your NPM account:
    npm login
  2. (Optional) If publishing under your scope, rename "name" in package.json to @your-username/retry-fetch-pro:
    npm publish --access public
  3. Or publish directly:
    npm publish

💖 Support the Project

If you find this package useful, consider sponsoring its ongoing development and maintenance: 👉 Sponsor @Piratha97 on GitHub Sponsors

📄 License

MIT © 2026