@febin52/rate-limiter-flexible
v1.0.2
Published
In-memory token bucket & leaky bucket rate limiter for Node APIs & frontend UI actions.
Maintainers
Readme
🚦 @febin52/rate-limiter-flexible
In-memory token bucket rate limiter for Node APIs, web workers, and frontend UI user action throttling.
A flexible, high-throughput Token Bucket rate limiter designed to prevent API spamming, brute-force requests, and UI event floods.
🚀 Features
- ⚡ Token Bucket Algorithm: Smooth traffic spikes and enforce strict rate limits.
- 📦 Zero Dependencies: Lightweight, memory-conscious data structures.
- 🎯 Simple API: Easy boolean
tryConsume()checking.
📦 Installation
npm install @febin52/rate-limiter-flexible💡 Usage
import { RateLimiter } from '@febin52/rate-limiter-flexible';
// Allow 5 tokens per 1000ms (1 second)
const limiter = new RateLimiter({ tokensPerInterval: 5, intervalMs: 1000 });
if (limiter.tryConsume(1)) {
// Request allowed
handleApiCall();
} else {
// Rate limit exceeded (429)
console.warn('Rate limit exceeded. Please try again later.');
}🔗 Links
- NPM Package: https://www.npmjs.com/package/@febin52/rate-limiter-flexible
- GitHub Repository: https://github.com/febin52/rate-limiter-flexible
- Issue Tracker: https://github.com/febin52/rate-limiter-flexible/issues
📄 License
MIT © Febin Francis
