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

@systemix/rate-limit

v0.1.1

Published

Rate limiting with fixed-window, sliding-window, and token-bucket algorithms, plus Express middleware. Zero dependencies. Part of the Systemix toolkit.

Downloads

348

Readme

@systemix/rate-limit

npm

@systemix/rate-limit provides rate limiting with fixed-window, sliding-window, and token-bucket algorithms, a pluggable store, and Express-compatible middleware. Built entirely on platform primitives. Zero dependencies.

Features

  • Three Algorithms: Fixed-window (default), sliding-window (rolling log), and token-bucket (continuous refill) — pick per use case.
  • Pluggable Storage: In-memory Map store out of the box; implement RateLimitStore for Redis or databases.
  • Express-Compatible Middleware: Dependency-free structural types work with Express, Next.js route handlers, and plain http. Emits standard RateLimit-* and Retry-After headers.
  • Generic Function Wrapper: Rate-limit any function with withRateLimit.
  • Rich Results: Every check returns { success, limit, remaining, reset, retryAfter }.
  • Zero Dependencies: Purely built with platform primitives.
  • TypeScript Ready: Full type definitions included.

Installation

pnpm add @systemix/rate-limit

or

npm install @systemix/rate-limit

From GitHub Packages (add to .npmrc: @shahadathhs:registry=https://npm.pkg.github.com):

pnpm add @shahadathhs/rate-limit

Use @shahadathhs/rate-limit in imports.

Usage

Basic Rate Limiting

import { createRateLimiter } from '@systemix/rate-limit';

const limiter = createRateLimiter({ limit: 5, windowMs: 60_000 });

const result = limiter.limit('user:42');
// → { success: true, limit: 5, remaining: 4, reset: 1700000000000, retryAfter: 0 }

if (!result.success) {
  console.log(`Retry in ${result.retryAfter}ms`);
}

Express Middleware

import { expressRateLimit } from '@systemix/rate-limit';

app.use(
  '/api',
  expressRateLimit({
    limit: 100,
    windowMs: 60_000,
    statusCode: 429,
    message: { error: 'Slow down!' },
    keyGenerator: (req) => req.ip ?? 'unknown',
  }),
);

Generic Function Wrapper

import { createRateLimiter, withRateLimit } from '@systemix/rate-limit';

const limiter = createRateLimiter({ limit: 10, windowMs: 60_000 });

const getUser = withRateLimit(fetchUser, limiter, (userId) => userId);
// throws RateLimitExceededError when the limit is hit

Pluggable Store

const limiter = createRateLimiter({
  limit: 100,
  windowMs: 60_000,
  store: new RedisStore(), // implements RateLimitStore
});

API Reference

createRateLimiter(options): RateLimiter

| Option | Type | Default | Description | | :---------- | :----------------------------------------------------- | :--------------- | :----------------------------------------- | | limit | number | — (required) | Max requests per window (bucket capacity). | | windowMs | number | — (required) | Window size in milliseconds. | | algorithm | 'fixed-window' \| 'sliding-window' \| 'token-bucket' | 'fixed-window' | Rate limiting algorithm. | | store | RateLimitStore | in-memory Map | Custom storage backend. |

Returns a limiter with:

| Method | Description | | :-------------- | :-------------------------------------- | | limit(key) | Records a hit and returns the verdict. | | peek(key) | Reads state without recording a hit. | | resetKey(key) | Clears the state for one key. | | resetAll() | Clears all state. | | sweep() | Removes expired entries from the store. |

expressRateLimit(options)

Express-compatible middleware. Extra options beyond the limiter's:

| Option | Type | Default | Description | | :---------------- | :---------------- | :---------------------------------- | :----------------------------------- | | keyGenerator | (req) => string | request IP | Extracts the rate limit key. | | message | unknown | { message: 'Too many requests…' } | Body for blocked requests. | | statusCode | number | 429 | HTTP status for blocked requests. | | standardHeaders | boolean | true | Emits RateLimit-* / Retry-After. |

withRateLimit(handler, limiter, keyGenerator?)

Wraps any function; blocked calls throw RateLimitExceededError (carries retryAfter and limit).

Algorithms

| Algorithm | Behavior | Best for | | :--------------- | :--------------------------------------------- | :----------------------- | | fixed-window | Counter resets every window — lowest memory | Simple request caps | | sliding-window | Rolling log of timestamps — no boundary bursts | Fair, smooth quotas | | token-bucket | Continuous refill — tolerates short bursts | APIs with bursty traffic |

License

MIT © shahadathhs