1.0.0 • Published 5 years ago

elimiter v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

NPM version build status Test coverage David deps node version npm download npm license

node-elimiter

Easy rate limiter.

Install

$ npm install elimiter --save

How to use

import Limiter from "elimiter";

const db = new Redis();

// limit 5 call in 60s (60*1000ms)
const limiter = new Limiter(db, { id: "ip", max: 5, duration: 60 * 1000 });

const res = await limit.get(); // limit.get(req.ip), limit(userid)
if(res.remaining < 1) throw new Errror("out of limit");
// continue
// Get with reset and resetMs
const res = await limit.get({ reset: true });
console.log(res)
// { count: 0, remaining: 5, total: 5, reset: 1546438588, resetMs: 1546438588062 }
if(res.remaining < 1) throw new Errror("out of limit");
// continue