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 🙏

© 2025 – Pkg Stats / Ryan Hefner

easybro-rate-limiter

v1.0.2

Published

A simple and efficient rate limiter using the token bucket algorithm for Express and other Node.js servers.

Downloads

7

Readme

easybroRateLimiter

A simple, lightweight, in-memory rate limiting middleware for Express.js using the Token Bucket algorithm.
It helps protect your API from abuse by limiting the number of requests a client can make within a given time frame.

https://www.npmjs.com/package/easybro-rate-limiter


📦 Installation

npm install easy-rate-limiter
# or
yarn add easy-rate-limiter

🚀 Quick Start

import express from 'express';
import { easyRateLimiter } from 'easy-rate-limiter';

const app = express();

// Apply rate limiter to all routes
app.use(easyRateLimiter({
  capacity: 5,       // Max tokens
  refillRate: 1,     // Tokens per second
}));

app.get('/', (req, res) => {
  res.send('Hello, world!');
});

app.listen(3000, () => console.log('Server running on port 3000'));

⚙️ Options

easyRateLimiter accepts the following configuration options:

| Option | Type | Default Value | Description | | -------------- | -------------------------- | ---------------------------------------------- | ----------------------------------------------------------------------------- | | capacity | number | 10 | Maximum number of tokens in the bucket (burst limit). | | refillRate | number | 1 | Number of tokens added per second. | | keyGenerator | (req: Request) => string | (req) => req.ip | Function that generates a unique key per client (e.g., IP, user ID, API key). | | message | string | "Too many requests. Please try again later." | Error message returned when the limit is exceeded. |


🛠 How It Works (Token Bucket Algorithm)

  • Bucket Capacity (capacity): The maximum number of requests that can be made instantly (burst).
  • Refill Rate (refillRate): How many tokens are added back per second.
  • Token Consumption: Each incoming request consumes one token.
  • Limit Exceeded: If the bucket has no tokens left, the request is rejected with HTTP 429.

Example:

Capacity = 5, Refill Rate = 1/sec

A client can make up to 5 requests instantly, then 1 request per second thereafter.

🔑 Custom Key Generation

You can identify clients by something other than their IP. For example, using an API key:

app.use(easyRateLimiter({
  capacity: 20,
  refillRate: 5,
  keyGenerator: (req) => req.headers['x-api-key'] as string,
  message: 'Rate limit exceeded for your API key.'
}));

🎯 Apply to Specific Routes

Instead of applying globally, you can apply it per-route:

const apiLimiter = easyRateLimiter({ capacity: 3, refillRate: 1 });

app.get('/public', (req, res) => res.send('Public route, no limit'));
app.get('/protected', apiLimiter, (req, res) => res.send('Protected route'));

🧪 Example With Express Router

import express from 'express';
import { easyRateLimiter } from 'easy-rate-limiter';

const router = express.Router();
const limiter = easyRateLimiter({ capacity: 5, refillRate: 2 });

router.get('/data', limiter, (req, res) => {
  res.json({ data: 'Some rate-limited data' });
});

export default router;

📜 API Responses

When the limit is reached, the middleware responds with:
Status: 429 Too Many Requests

{
  "error": "Too many requests. Please try again later."
}

⚠️ Notes & Limitations

  • This implementation is in-memory. It does not persist data across server restarts or multiple instances.
  • Suitable for single-instance deployments or low-scale APIs.
  • For distributed setups, integrate with a shared store like Redis (planned future enhancement).

🤝 Contributing

Contributions are welcome! Please open an issue or submit a pull request.


Made with ❤️ by Vishal Vishwakarma