Skip to content

IP based token bucket rate limiter / throttler.

Notifications You must be signed in to change notification settings

D3visionNL/ip-token-bucket

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ip-token-bucket

IP based token bucket rate limiter / throttler. Read more about Token Buckets.

Usage

Install the package by typing npm i @d3vision/ip-token-bucket in your project folder.

Setup

const TokenBucket = require("ip-token-bucket");

const bucket = new TokenBucket({
  maxBurst: 5, // Maximum burst (bucket size) that is accepted
  perSecond: 1, // How many tokens will be added every 1s
});

// Take one token out if 127.0.0.1 ip's bucket
const hasTokens = bucket.take("127.0.0.1");

if (hasTokens) {
  console.log("User had atleast one token!");
} else {
  console.log("User didn't have tokens left.");
}

About

IP based token bucket rate limiter / throttler.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%