{"id":13989848,"url":"https://github.com/tj/node-ratelimiter","last_synced_at":"2025-04-13T11:48:08.855Z","repository":{"id":517678,"uuid":"14376277","full_name":"tj/node-ratelimiter","owner":"tj","description":"Abstract rate limiter for nodejs","archived":false,"fork":false,"pushed_at":"2022-12-30T17:15:51.000Z","size":210,"stargazers_count":720,"open_issues_count":11,"forks_count":62,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-11T07:10:07.418Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tj.png","metadata":{"files":{"readme":"Readme.md","changelog":"History.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-13T20:59:49.000Z","updated_at":"2025-03-23T05:42:39.000Z","dependencies_parsed_at":"2023-01-13T10:25:18.716Z","dependency_job_id":null,"html_url":"https://github.com/tj/node-ratelimiter","commit_stats":null,"previous_names":["visionmedia/node-ratelimiter"],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fnode-ratelimiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fnode-ratelimiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fnode-ratelimiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tj%2Fnode-ratelimiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tj","download_url":"https://codeload.github.com/tj/node-ratelimiter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248573546,"owners_count":21126857,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-09T13:02:06.984Z","updated_at":"2025-04-13T11:48:08.830Z","avatar_url":"https://github.com/tj.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Libraries"],"sub_categories":["Services"],"readme":"# ratelimiter\n\nRate limiter for Node.js backed by Redis.\n  \n\u003e **NOTE**: Promise version available at [async-ratelimiter](https://github.com/microlinkhq/async-ratelimiter).\n\n[![Build Status](https://travis-ci.org/tj/node-ratelimiter.svg)](https://travis-ci.org/tj/node-ratelimiter)\n\n## Release Notes\n[v3.4.1](https://github.com/tj/node-ratelimiter/tree/v3.4.1) - [#55](/../../issues/55) by [@barwin](https://github.com/barwin) - Remove splice operation.\n\n[v3.3.1](https://github.com/tj/node-ratelimiter/tree/v3.3.1) - [#51](/../../issues/51) - Remove tidy option as it's always true.\n\n[v3.3.0](https://github.com/tj/node-ratelimiter/tree/v3.3.0) - [#47](/../../pull/47) by [@penghap](https://github.com/penghap) - Add tidy option to clean old records upon saving new records. Drop support in node 4.\n\n[v3.2.0](https://github.com/tj/node-ratelimiter/tree/v3.2.0) - [#44](/../../pull/44) by [@xdmnl](https://github.com/xdmnl) - Return accurate reset time for each limited call.\n\n[v3.1.0](https://github.com/tj/node-ratelimiter/tree/v3.1.0) - [#40](/../../pull/40) by [@ronjouch](https://github.com/ronjouch) - Add reset milliseconds to the result object.\n\n[v3.0.2](https://github.com/tj/node-ratelimiter/tree/v3.0.0) - [#33](/../../pull/33) by [@promag](https://github.com/promag) - Use sorted set to limit with moving window.\n\n[v2.2.0](https://github.com/tj/node-ratelimiter/tree/v2.2.0) - [#30](/../../pull/30) by [@kp96](https://github.com/kp96) - Race condition when using `async.times`.\n\n[v2.1.3](https://github.com/tj/node-ratelimiter/tree/v2.1.3) - [#22](/../../pull/22) by [@coderhaoxin](https://github.com/coderhaoxin) - Dev dependencies versions bump.\n\n[v2.1.2](https://github.com/tj/node-ratelimiter/tree/v2.1.2) - [#17](/../../pull/17) by [@waleedsamy](https://github.com/waleedsamy) - Add Travis CI support.\n\n[v2.1.1](https://github.com/tj/node-ratelimiter/tree/v2.1.1) - [#13](/../../pull/13) by [@kwizzn](https://github.com/kwizzn) - Fixes out-of-sync TTLs after running decr().\n\n[v2.1.0](https://github.com/tj/node-ratelimiter/tree/v2.1.0) - [#12](/../../pull/12) by [@luin](https://github.com/luin) - Adding support for ioredis.\n\n[v2.0.1](https://github.com/tj/node-ratelimiter/tree/v2.0.1) - [#9](/../../pull/9) by [@ruimarinho](https://github.com/ruimarinho) - Update redis commands to use array notation.\n\n[v2.0.0](https://github.com/tj/node-ratelimiter/tree/v2.0.0) - **API CHANGE** - Change `remaining` to include current call instead of decreasing it. Decreasing caused an off-by-one problem and caller could not distinguish between last legit call and a rejected call.\n\n## Requirements\n\n- Redis 2.6.12+\n- Node 8.0.0+\n\n## Installation\n\n```\n$ npm install ratelimiter\n```\n\n## Example\n\n Example Connect middleware implementation limiting against a `user._id`:\n\n```js\nvar id = req.user._id;\nvar limit = new Limiter({ id: id, db: db });\nlimit.get(function(err, limit){\n  if (err) return next(err);\n\n  res.set('X-RateLimit-Limit', limit.total);\n  res.set('X-RateLimit-Remaining', limit.remaining - 1);\n  res.set('X-RateLimit-Reset', limit.reset);\n\n  // all good\n  debug('remaining %s/%s %s', limit.remaining - 1, limit.total, id);\n  if (limit.remaining) return next();\n\n  // not good\n  var delta = (limit.reset * 1000) - Date.now() | 0;\n  var after = limit.reset - (Date.now() / 1000) | 0;\n  res.set('Retry-After', after);\n  res.send(429, 'Rate limit exceeded, retry in ' + ms(delta, { long: true }));\n});\n```\n\n## Result Object\n - `total` - `max` value\n - `remaining` - number of calls left in current `duration` without decreasing current `get`\n - `reset` - time since epoch in seconds at which the rate limiting period will end (or already ended)\n - `resetMs` - time since epoch in milliseconds at which the rate limiting period will end (or already ended)\n\n## Options\n\n - `id` - the identifier to limit against (typically a user id)\n - `db` - redis connection instance\n - `max` - max requests within `duration` [2500]\n - `duration` - of limit in milliseconds [3600000]\n\n# License\n\n  MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftj%2Fnode-ratelimiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftj%2Fnode-ratelimiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftj%2Fnode-ratelimiter/lists"}