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

@marufzak/rlimiter

v3.0.0

Published

Rate limiter for NodeJS

Downloads

837

Readme

@marufzak/rlimiter

Redis-backed rate limiter for Node.js with multiple rate limiting strategies.

Installation

npm install @marufzak/rlimiter redis

Usage

See the examples folder for usage examples:

Error Handling

By default, requests are rejected when Redis fails. You can customize this behavior:

const strategy = new FixedWindow({
  maxTokens: 10,
  windowSizeMs: 60_000,
  redisClient,
  onError: error => {
    console.error('Rate limiter error:', error);
    return 'allow'; // or 'reject'
  },
});

Default behavior: Requests are rejected on Redis errors to maintain security.

Fail open (allow requests):

onError: () => 'allow';

Fail closed (reject requests):

onError: () => 'reject'; // Default

API

FixedWindow(options)

Options:

  • maxTokens - Maximum number of requests allowed per window
  • windowSizeMs - Window duration in milliseconds
  • redisClient - Redis client instance
  • onError - Optional error handler that returns 'allow' or 'reject' (default: rejects)

Methods:

  • check({ key }) - Returns object:
    • isAllowed - true if allowed, false if rate limited
    • remainingRequests - Number of remaining requests in current window
    • remainingTime - Time in milliseconds until retry is possible

TokenBucket(options)

Options:

  • capacity - Maximum number of tokens in the bucket
  • replenishRate - Tokens added per second
  • redisClient - Redis client instance
  • onError - Optional error handler that returns 'allow' or 'reject' (default: rejects)

Methods:

  • check({ bucketKey, timestampKey }) - Returns object:
    • isAllowed - true if allowed, false if rate limited
    • remainingRequests - Number of remaining tokens in bucket
    • remainingTime - Time in milliseconds until retry is possible

LeakyBucket(options)

Options:

  • capacity - Maximum queue size
  • leakRate - Requests processed per second
  • redisClient - Redis client instance
  • onError - Optional error handler that returns 'allow' or 'reject' (default: rejects)

Methods:

  • check({ queueKey, timestampKey }) - Returns object:
    • isAllowed - true if allowed, false if rate limited
    • remainingRequests - Number of available slots in queue
    • remainingTime - Time in milliseconds until retry is possible

SlidingWindowCount(options)

Requires Redis 7.4+

Options:

  • limit - Maximum number of requests allowed per window
  • windowSizeMs - Total window duration in milliseconds
  • subWindowSizeMs - Sub-window duration in milliseconds
  • redisClient - Redis client instance
  • onError - Optional error handler that returns 'allow' or 'reject' (default: rejects)

Methods:

  • check({ hashKey }) - Returns object:
    • isAllowed - true if allowed, false if rate limited
    • remainingRequests - Number of remaining requests in the current window
    • remainingTime - Time in milliseconds until retry is possible

SlidingWindowLog(options)

Options:

  • capacity - Maximum number of requests allowed per window
  • windowSizeMs - Sliding window duration in milliseconds
  • redisClient - Redis client instance
  • onError - Optional error handler that returns 'allow' or 'reject' (default: rejects)

Methods:

  • check({ queueKey }) - Returns object:
    • isAllowed - true if allowed, false if rate limited
    • remainingRequests - Number of remaining requests in the current window
    • remainingTime - Time in milliseconds until retry is possible

koaRateLimiterMiddleware(options)

Options:

  • strategy - Rate limiting strategy instance (FixedWindow, TokenBucket, LeakyBucket, SlidingWindowLog, or SlidingWindowCount)
  • getKey - Function to extract rate limit key(s) from context (returns strategy-specific check options)
  • onLimit - Optional callback when rate limit exceeded
  • onProceed - Optional callback when request allowed

Returns 429 status with X-Ratelimit-Retry-After header (seconds) and sets X-Ratelimit-Remaining header when rate limited.

License

MIT