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

paced-fetch

v0.1.0

Published

A fetch that paces requests per API host (rate, concurrency, gap), honors Retry-After, and is configured the same way from env in every server that uses it

Readme

paced-fetch

A fetch that is polite to the APIs it calls. Each API host gets a limiter (requests per window, requests in flight, a minimum gap), 429s are waited out the way the server asks, and every program that uses it is configured with the same environment variables.

It was written for MCP servers that read web APIs (Substack, Medium, Spotify, Deezer…), each of which had grown its own retry loop with its own rules. No dependencies.

import { pacedFetch, paceFromEnv } from "paced-fetch";

const { pace, warnings } = paceFromEnv("SUBSTACK", { concurrency: 3 }); // env over these defaults
const fetch = pacedFetch({
  defaults: pace,
  hosts: { "deezer.com": { rate: { count: 50, perMs: 5000 } } }, // Deezer's documented limit
  onEvent: (e) => console.error(`${e.type} ${e.host} ${e.status ?? e.error} (waiting ${e.waitMs} ms)`),
});
const res = await fetch("https://example.substack.com/api/v1/archive");

What it does

| Situation | Behavior | |---|---| | Before each request | Waits for the host's limiter: concurrency, rate (sliding window), minGapMs | | 429 | Retries after Retry-After (seconds or a date), else a backoff with jitter (1 s, 3 s, 10 s). Also widens that host's gap (250 ms, doubling to 10 s); every 20 successes in a row halve it again | | 429 with a wait longer than maxRetryWaitMs | Doesn't wait: throws RateLimitedError (with until), and every later call to that host throws at once until then, without sending anything | | 5xx, network error | Retried for idempotent requests only (GET, HEAD, OPTIONS, PUT, DELETE, or what isIdempotent says, e.g. GraphQL reads) | | Anything else, or retries run out | The response is returned as is, so the caller's own error handling still runs |

timeoutMs times out each attempt from when it's actually sent, and such a timeout is retried like a network error. A timeout or abort from the caller's own signal is never retried, and it also counts time spent waiting for the limiter, so prefer timeoutMs. Request bodies are sent again on a retry, so pass strings, not streams.

Hosts not named in hosts each get their own limiter with the defaults. A hosts key is a hostname, or a domain that covers its subdomains (deezer.com covers api.deezer.com).

Environment variables

paceFromEnv(prefix, defaults) reads these over the program's defaults:

| Variable | Example | | |---|---|---| | <PREFIX>_RATE | 60/min, 10/s, 50/5s | Requests started per window | | <PREFIX>_CONCURRENCY | 3 | Requests in flight | | <PREFIX>_MIN_GAP | 250ms | Between request starts | | <PREFIX>_RETRIES | 3 | Retries after the first try | | <PREFIX>_MAX_RETRY_WAIT | 60s, 5min | Longest wait worth sitting through |

off (or 0) removes a rate, concurrency or gap limit. A value that doesn't parse is ignored and listed in warnings, so a typo doesn't stop a server from starting.

Development

npm install
npm test

Node 26 or later. MIT licensed.