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
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
332 Stars
171 Commits
23 Forks
2 Watchers
1 Branches
11 Contributors
Updated on Jul 02, 2025
Latest Version
1.6.1
Package Id
async-ratelimiter@1.6.1
Unpacked Size
12.49 kB
Size
4.71 kB
File Count
6
NPM Version
10.9.2
Node Version
22.16.0
Published on
Jul 02, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Rate limit made simple, easy, async. Based on ratelimiter.
1$ npm install async-ratelimiter --save
The most straightforward way to use the rate limiter:
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}
For scenarios where you want to check the limit status before consuming a request, you should to pass { peek: true }
:
1const apiQuota = async (req, res, next) => {
2 const clientIp = getClientIp(req)
3
4 // Check rate limit status without consuming a request
5 const status = await rateLimiter.get({ id: clientIp, peek: true })
6
7 if (status.remaining === 0) {
8 return sendFail({
9 req,
10 res,
11 code: HTTPStatus.TOO_MANY_REQUESTS,
12 message: MESSAGES.RATE_LIMIT_EXCEDEED()
13 })
14 }
15
16 // Consume a request
17 const limit = await rateLimiter.get({ id: clientIp })
18
19 if (!res.writableEnded) {
20 res.setHeader('X-Rate-Limit-Limit', limit.total)
21 res.setHeader('X-Rate-Limit-Remaining', limit.remaining)
22 res.setHeader('X-Rate-Limit-Reset', limit.reset)
23 }
24
25 return next(req, res)
26}
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.duration
How long keep records of requests in milliseconds. If provided, it overrides the default duration
value.
Type: boolean
Default: false
When set to true
, returns the current rate limit status without consuming a request. This is useful for checking the current rate limit status before deciding whether to proceed with an operation.
It provides the command definition so you can load it into any ioredis instance:
1const Redis = require('ioredis') 2const redis = new Redis(uri, { 3 scripts: { ...require('async-ratelimiter').defineCommand } 4})
async-ratelimiter © microlink.io, released under the MIT License.
Authored and maintained by Kiko Beats with help from contributors.
microlink.io · GitHub microlink.io · X @microlinkhq
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
17 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 10
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/27 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
dangerous workflow patterns detected
Details
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 2025-06-30
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