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

@sibilsoren/gatekeeper

v1.0.0

Published

Production-grade, Redis-backed API rate limiting middleware for Express

Readme

@sibilsoren/gatekeeper

npm version CI License: MIT

Production-grade, Redis-backed API rate limiting middleware for Express.

  • 3 algorithms — Fixed Window, Sliding Window Counter, Token Bucket
  • 🔴 Redis-backed — Distributed rate limiting across multiple servers
  • 💾 In-memory fallback — Zero-config for development and single-server
  • 🛡️ Fail-open — If Redis goes down, requests are allowed (not blocked)
  • 📊 Standard headersX-RateLimit-* and Retry-After out of the box
  • 🎯 Flexible keys — Rate limit by IP, API key, user ID, or custom function
  • 🪶 Tiny — Zero runtime dependencies (ioredis is an optional peer dep)

Install

npm install @sibilsoren/gatekeeper

For Redis support (optional):

npm install @sibilsoren/gatekeeper ioredis

Quick Start

import express from 'express';
import { gatekeeper } from '@sibilsoren/gatekeeper';

const app = express();

// 100 requests per minute per IP (sliding window)
app.use(gatekeeper());

// Custom limits per route
app.post('/auth/login', gatekeeper({
  limit: 5,
  window: '15m',
  message: 'Too many login attempts. Try again later.',
}));

app.listen(3000);

Algorithms

Sliding Window Counter (default)

The most accurate algorithm. Prevents boundary burst attacks by weighting the previous window's count.

app.use(gatekeeper({
  algorithm: 'sliding-window',  // default
  limit: 100,
  window: '1m',
}));

Fixed Window

Simplest algorithm. Resets the counter at the start of each window.

app.use(gatekeeper({
  algorithm: 'fixed-window',
  limit: 100,
  window: '1m',
}));

Token Bucket

Best for APIs with burst traffic. Tokens refill at a steady rate.

app.use(gatekeeper({
  algorithm: 'token-bucket',
  capacity: 50,     // Max burst
  refillRate: 10,   // 10 tokens per second
}));

Redis Store (Distributed)

For multi-server deployments, use the Redis store:

import { gatekeeper, RedisStore } from '@sibilsoren/gatekeeper';
import Redis from 'ioredis';

const redis = new Redis('redis://localhost:6379');

app.use(gatekeeper({
  store: new RedisStore(redis),
  limit: 100,
  window: '1m',
}));

If Redis goes down, Gatekeeper fails open — requests are allowed through. Your API stays up even if Redis doesn't.

Options

| Option | Type | Default | Description | |---|---|---|---| | limit | number | 100 | Max requests per window | | window | string \| number | "1m" | Window size ("30s", "5m", "1h", or ms) | | algorithm | string | "sliding-window" | "fixed-window", "sliding-window", "token-bucket" | | store | Store | MemoryStore | Storage backend | | keyGenerator | (req) => string | req.ip | Function to generate rate limit key | | message | string | "Too Many Requests" | Error message on 429 | | prefix | string | "gk:" | Key prefix in storage | | skip | (req) => boolean | () => false | Skip rate limiting for certain requests | | handler | function | null | Custom 429 response handler | | headers | boolean | true | Include X-RateLimit-* headers | | statusCode | number | 429 | HTTP status when limited | | capacity | number | 100 | Token bucket capacity | | refillRate | number | 10 | Tokens per second (token bucket) |

Examples

Rate limit by API key

app.use(gatekeeper({
  keyGenerator: (req) => req.headers['x-api-key']?.toString() || req.ip,
}));

Skip health checks

app.use(gatekeeper({
  skip: (req) => req.path === '/health',
}));

Custom error response

app.use(gatekeeper({
  handler: (req, res, next, info) => {
    res.status(429).json({
      error: 'Rate Limited',
      limit: info.limit,
      remaining: info.remaining,
      retryAfter: info.retryAfter,
    });
  },
}));

Different limits per route

// Strict for auth
app.use('/auth', gatekeeper({ limit: 5, window: '15m' }));

// Generous for read-only
app.use('/api', gatekeeper({ limit: 1000, window: '1m' }));

Response Headers

Every response includes rate limit headers:

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 42
X-RateLimit-Reset: 1718042520

When rate limited (429):

Retry-After: 30

Roadmap

See ROADMAP.md for planned features and improvements.

Contributing

Contributions are welcome! See CONTRIBUTING.md for details.

License

MIT © SibilSoren