@adt-it/rate-limiter
v1.1.0
Published
provides request logging and rate limit checks
Downloads
7
Maintainers
Readme
rate-limiter
toolbox for express boilerplate functions
Usage Example
const clsRateLimiter = require('@adt-it/rate-limiter');
let rateLimiter = new clsRateLimiter(10, 60); //max 10 requests every 10 seconds
app.use(async (req, res, next)=>{
if(rateLimiter.log(req.validatedClientIp)){
return next(new httpError('over quota', 429));
}
});
Doc
Table of Contents
RateLimiter
Create with parameters limit and timespanS
Parameters
limit
integertimespanS
integer
log
logs a request from source for timespanS seconds
Parameters
source
stringtimespanS
integer , defaults to defaultTimespanSlimit
integer , defaults to defaultLimit
Returns Boolean returns this.check(source, limit)
check
Parameters
source
stringlimit
integer , defaults to defaultLimit
Returns Boolean returns true if limit is exeeded
get
Returns used quota of source
Parameters
source
string
Returns integer used quota
getDiff
returns difference from quota used by source to limit
Parameters
source
stringlimit
integer , defaults to defaultLimit
Returns integer