elimiter
v1.0.0
Published
easy node rate limiter
Downloads
1
Readme
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