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

@ratelock/express

v0.1.0

Published

Rate limiting middleware for Express — engine-agnostic, powered by any RateLock limiter

Readme

@ratelock/express

Rate limiting middleware for Express 4 and 5. Bring any RateLock limiter; the middleware stays engine-agnostic.

Why

RateLock engines (@ratelock/local, @ratelock/redis, @ratelock/postgres) expose limiters; this package turns any of them into Express middleware. Zero runtime dependencies beyond Express itself. Swap engines without touching your routes.

Install

pnpm add @ratelock/express @ratelock/local   # or @ratelock/redis, @ratelock/postgres

Quick start

import express from 'express'
import { rateLimit } from '@ratelock/express'
import { fixedWindow } from '@ratelock/redis'

const app = express()

app.use(
    '/api',
    rateLimit({
        // Lazy factory: the engine initializes on the first matched request.
        limiter: () => fixedWindow({ url: process.env.REDIS_URL!, limit: 100, windowMs: 60_000 }),
        limit: 100, // only used for the *Limit headers
        keyGenerator: req => req.ip ?? 'anon',
    })
)

app.get('/api/things', (_req, res) => res.json({ things: [] }))

Already have an instance? Pass it directly:

const limiter = await fixedWindow({ limit: 100, windowMs: 60_000 })
app.use('/api', rateLimit({ limiter }))

Express 4 and 5

One package covers both majors. The middleware always forwards async failures through next(err), which Express 4 requires and Express 5 appreciates. Tested against both majors on every change.

Options

| Option | Type | Default | Description | | ---------------- | ------------------------------------------------ | --------------------- | ------------------------------------------------------------------------------------------------------------------- | | limiter | Limiter or () => Limiter \| Promise<Limiter> | required | Any RateLock limiter. A factory is memoized and invoked once, on the first matched request. | | keyGenerator | (req: Request) => string \| Promise<string> | req.ip | Identifier the request is counted against. Falls back to a shared 'anonymous' bucket when the address is unknown. | | headers | 'both' \| 'rfc' \| 'legacy' \| false | 'both' | RateLimit-* (RFC 9331) and/or X-RateLimit-* families. | | limit | number | (none) | Quota, used only to emit the *Limit headers (results do not carry it). | | denyStatusCode | number | 429 | Status returned when the quota is exhausted. | | message | string | 'Too Many Requests' | JSON body of the denial response. |

Denial responses include Retry-After (seconds) whenever the result exposes a reset/refill time.

Headers

| Family | Headers | | ----------- | ----------------------------------------------------------------- | | RFC 9331 | RateLimit-Limit, RateLimit-Remaining, RateLimit-Reset | | Legacy | X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset | | Denial only | Retry-After |

RateLimit-Reset is always expressed in seconds. Token bucket results project floor(tokens) onto Remaining and the refill time onto Reset.

Identifiers and proxies

The default key reads req.ip, which honors your app's trust proxy setting. Behind a proxy without trust configuration, every client shares the proxy's address and one bucket. Set trust proxy correctly or provide a keyGenerator. Never read raw x-forwarded-for yourself: attackers forge it per-request to bypass limits.

License

MIT · Hakim Saoudi