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

rate-queue

v1.2.2

Published

A powerful rate limiter with concurrency control, priority queues, task scheduling, and Redis clustering support

Readme

rate-queue

Control how many tasks run at once and how fast they start. Use it when you're calling an API that has rate limits, or when you want to avoid overloading a service.

In production Node usually runs on multiple instances (containers, PM2 cluster, several servers). Each process has its own memory, so you need a Redis-backed limiter to share one limit across all of them. Use DistributedRateLimiter for that.

Install

npm install rate-queue

Docs — Full guides and API reference: docs.page/taukirsheikh/rate-queue

Production (multiple instances) — use Redis

import { DistributedRateLimiter } from 'rate-queue';

const limiter = new DistributedRateLimiter({
  maxConcurrent: 10,
  redis: { url: process.env.REDIS_URL || 'redis://localhost:6379' },
});
await limiter.ready();

const result = await limiter.schedule(() => fetch('https://api.example.com/data'));

All instances share the same queue and limits. If Redis is down, see the docs for waiting until Redis is back (recommended with multiple instances) vs falling back to in-memory (risky with multiple instances).

Single process (dev or one instance) — in-memory

import { RateLimiter } from 'rate-queue';

const limiter = new RateLimiter({
  maxConcurrent: 2,
  minTime: 500,
});
const result = await limiter.schedule(() => fetch('https://api.example.com/data'));

Sample: API function + limiter.schedule

Define an async function that calls your API, then run it through the limiter so it’s rate-limited:

import { DistributedRateLimiter } from 'rate-queue';

// Your API-calling function
async function fetchUser(id) {
  const res = await fetch(`https://api.example.com/users/${id}`);
  if (!res.ok) throw new Error(res.statusText);
  return res.json();
}

const limiter = new DistributedRateLimiter({
  maxConcurrent: 5,
  redis: { url: process.env.REDIS_URL || 'redis://localhost:6379' },
});
await limiter.ready();

// Run the function through the limiter — same args, same return
const user = await limiter.schedule(() => fetchUser(1));

schedule returns whatever your function returns, so you can destructure:

// With axios
const { data } = await limiter.schedule(async () => axios.request(config));

// Or wrap once and call many times
const limitedFetchUser = limiter.wrap(fetchUser);
const user1 = await limitedFetchUser(1);
const user2 = await limitedFetchUser(2);

What you can do

  • Limit concurrency (e.g. max 5 at a time).
  • Space out jobs (e.g. at least 100ms between starts).
  • Cap jobs per minute/hour with maxPerInterval and interval.
  • Use a token bucket with reservoir and refill options.
  • Give jobs priority so important work runs first.
  • Wrap any async function with limiter.wrap(fn).
  • Retry failed jobs with retryCount and retryDelay.
  • Cancel with limiter.cancel(jobId) or an AbortSignal.

Try the examples

npm run example        # in-memory limiter
npm run example:redis  # Redis (needs Redis running)

License — MIT