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

@streetjs/ratelimit

v1.0.0

Published

StreetJS rate limiting: sliding-window limiter middleware with global/per-IP/per-user scopes, a human-readable window parser, a @RateLimit method decorator, 429 + Retry-After/X-RateLimit-* headers, and pluggable in-memory or Redis backing stores.

Readme

@streetjs/ratelimit

The StreetJS rate limiter: sliding-window rate limiting as middleware, with global / per-IP / per-user scopes, a human-readable window parser, a @RateLimit method decorator, HTTP 429 responses with Retry-After and X-RateLimit-* headers, and pluggable in-memory or Redis backing stores. ESM.

This is the standalone home of the rate limiter that also backs the streetjs/ratelimit subpath. The streetjs framework re-exports this package, so there is a single source of truth.

Install

npm install @streetjs/ratelimit @streetjs/context @streetjs/store reflect-metadata

Scoped middleware (recommended)

import { rateLimit } from '@streetjs/ratelimit';

// 100 requests per minute, per client IP.
router.use(rateLimit({ scope: 'ip', requests: 100, window: '1m' }));

// Per authenticated user (falls back to IP for anonymous traffic).
router.use(rateLimit({ scope: 'user', requests: 1000, window: '1h' }));

// One global bucket for the whole app.
router.use(rateLimit({ scope: 'global', requests: 10_000, window: '1m' }));

window accepts a number (ms) or a string like "30s", "1m", "2h", "7d", "500ms". On the request that would exceed the limit the middleware throws a RateLimitException (HTTP 429) and sets Retry-After; permitted responses carry X-RateLimit-Limit, X-RateLimit-Reset, and X-RateLimit-Remaining.

Cross-instance enforcement (Redis)

import { rateLimit, RedisRateLimitStore } from '@streetjs/ratelimit';

const store = new RedisRateLimitStore(redisClient); // any { command(args) } client
router.use(rateLimit({ scope: 'ip', requests: 100, window: '1m', store }));

The Redis store keeps a sorted set per key (score = timestamp), trims with ZREMRANGEBYSCORE, counts with ZCARD, and bounds memory with PEXPIRE — mirroring the in-memory sliding window across instances.

The @RateLimit decorator

import { RateLimit, getRateLimitMeta } from '@streetjs/ratelimit';

class AuthController {
  @RateLimit({ requests: 5, window: 60_000 })
  login(ctx) { /* ... */ }
}

@RateLimit attaches street:rateLimit metadata; the router reads it via getRateLimitMeta(target, propertyKey) and enforces it at dispatch.

The class-based RateLimiter

The original hrtime-precise limiter is kept for direct use:

import { RateLimiter } from '@streetjs/ratelimit';

const limiter = new RateLimiter({ windowMs: 60_000, maxRequests: 100, trustProxy: false });
router.use(limiter.middleware());

By default the client key is the direct socket address (unspoofable). Set trustProxy: true only behind a trusted reverse proxy — the rightmost X-Forwarded-For entry (appended by the proxy) is used.

Exports

RateLimiter, rateLimit, RateLimitException, RateLimit, getRateLimitMeta, parseWindow, RedisRateLimitStore, and their option types.

Example

A complete runnable example lives in src/examples/integration.ts:

npm run example -w packages/ratelimit

License

MIT — see LICENSE.