Gathering detailed insights and metrics for async-ratelimiter
Gathering detailed insights and metrics for async-ratelimiter
Gathering detailed insights and metrics for async-ratelimiter
Gathering detailed insights and metrics for async-ratelimiter
npm install async-ratelimiter
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
320 Stars
154 Commits
23 Forks
3 Watching
2 Branches
10 Contributors
Updated on 23 Oct 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
10.4%
5,653
Compared to previous day
Last week
-1%
26,426
Compared to previous week
Last month
-12.2%
151,180
Compared to previous month
Last year
41.1%
1,009,383
Compared to previous year
Rate limit made simple, easy, async. Based on ratelimiter.
1$ npm install async-ratelimiter --save
A simple middleware implementation for whatever HTTP server:
1'use strict' 2 3const RateLimiter = require('async-ratelimiter') 4const { getClientIp } = require('request-ip') 5const Redis = require('ioredis') 6 7const rateLimiter = new RateLimiter({ 8 db: new Redis() 9}) 10 11const apiQuota = async (req, res, next) => { 12 const clientIp = getClientIp(req) 13 const limit = await rateLimiter.get({ id: clientIp }) 14 15 if (!res.writableEnded) { 16 res.setHeader('X-Rate-Limit-Limit', limit.total) 17 res.setHeader('X-Rate-Limit-Remaining', Math.max(0, limit.remaining - 1)) 18 res.setHeader('X-Rate-Limit-Reset', limit.reset) 19 } 20 21 return !limit.remaining 22 ? sendFail({ 23 req, 24 res, 25 code: HTTPStatus.TOO_MANY_REQUESTS, 26 message: MESSAGES.RATE_LIMIT_EXCEDEED() 27 }) 28 : next(req, res) 29}
It creates an rate limiter instance.
Required
Type: object
The redis connection instance.
Type: number
Default: 2500
The maximum number of requests within duration
.
Type: number
Default: 3600000
How long keep records of requests in milliseconds.
Type: string
Default: 'limit'
The prefix used for compound the key.
Type: string
The identifier to limit against (typically a user id).
You can pass this value using when you use .get
method as well.
Given an id
, returns a Promise with the status of the limit with the following structure:
total
: max
value.remaining
: number of calls left in current duration
without decreasing current get
.reset
: time since epoch in seconds that the rate limiting period will end (or already ended).Type: string
Default: this.id
The identifier to limit against (typically a user id).
Type: number
Default: this.max
The maximum number of requests within duration
. If provided, it overrides the default max
value. This is useful for custom limits that differ between IDs.
Type: number
Default: this.max
How long keep records of requests in milliseconds. If provided, it overrides the default duration
value.
async-ratelimiter © microlink.io, released under the MIT License.
Authored and maintained by Kiko Beats with help from contributors.
microlink.io · GitHub microlink.io · Twitter @microlinkhq
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/23 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More