limiter
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Limiter is a generic rate limiter for the web and node.js. It's useful in various scenarios such as when you're working with API clients, involved in web crawling, or undertaking any tasks that demand throttling. Two classes, RateLimiter and TokenBucket, are exposed by Limiter. TokenBucket offers a granular interface for rate limiting with an adjustable burst rate and drip rate, while RateLimiter builds on top of the token bucket and introduces a restriction on the maximum number of tokens that can be withdrawn each interval to conform with common API limitations.
To use Limiter, you first need to install it via yarn or npm:
yarn install limiter
Then you can import and use it in your application. A simple usage example where 150 requests per hour are allowed would look like this:
import { RateLimiter } from "limiter";
const limiter = new RateLimiter({ tokensPerInterval: 150, interval: "hour" });
async function sendRequest() {
const remainingRequests = await limiter.removeTokens(1);
callMyRequestSendingFunction(...);
}
Another usage example where one message can be sent every 250ms would look like this:
import { RateLimiter } from "limiter";
const limiter = new RateLimiter({ tokensPerInterval: 1, interval: 250 });
async function sendMessage() {
const remainingMessages = await limiter.removeTokens(1);
callMyMessageSendingFunction(...);
}
The official Limiter documentation is available within its GitHub repository (git://github.com/jhurliman/node-rate-limiter.git). Additionally, the documentation can be found within the README file on the package's npm page. It includes detailed installation and usage instructions, along with several code examples.