Socket
Book a DemoInstallSign in
Socket

bucket-rate-limit

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bucket-rate-limit

A lightweight, bucket-based rate limiter for JavaScript that controls request frequency with minimal overhead.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

Bucket Rate Limit

A lightweight, bucket-based rate limiter for Node.js that controls request frequency with minimal overhead.

Uses a token bucket: you start with capacity tokens and regain 1 token every intervalMs until the bucket is full again. Call wait() to block until a token is available.

Install

npm i bucket-rate-limit

API

const limiter = new BucketRateLimiter(capacity, intervalMs)

Create a new rate limiter, with parameters:

  • capacity: maximum number of tokens (burst size)
  • intervalMs: milliseconds per token refill (refills 1 token each interval)

For example:

  • capacity = 1 and intervalMs = 200 allows 5 requests per second, and no bursts.
  • capacity = 10 and intervalMs = 200 allows bursts up to 10 requests, but still limits long-term throughput to 5 requests per second.
  • capacity = 10 and intervalMs = 1000 also allows bursts up to 10 requests, but long-term throughput of just 1 request per second.

await limiter.wait({ abort } = {})

Wait until a token is available. Returns immediately if the capacity is available.

Optional abort: a promise that can cause the wait to abort by rejecting. Default is to not support aborting (so it will keep waiting until a token is available).

limiter.destroy()

Destroy the rate limiter: stops refilling the bucket and aborts any pending waits.

License

Apache-2.0

FAQs

Package last updated on 26 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts