{"id":20516175,"url":"https://github.com/aftership/rate-limiter","last_synced_at":"2025-04-14T00:35:33.705Z","repository":{"id":28859150,"uuid":"32383251","full_name":"AfterShip/rate-limiter","owner":"AfterShip","description":"Redis rate limiter for Node.js","archived":false,"fork":false,"pushed_at":"2023-03-04T03:35:06.000Z","size":1658,"stargazers_count":11,"open_issues_count":2,"forks_count":5,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-04-11T16:37:10.761Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AfterShip.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-03-17T09:22:30.000Z","updated_at":"2023-12-16T18:26:57.000Z","dependencies_parsed_at":"2024-06-21T05:53:34.990Z","dependency_job_id":null,"html_url":"https://github.com/AfterShip/rate-limiter","commit_stats":null,"previous_names":["aftership/rlimit"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AfterShip%2Frate-limiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AfterShip%2Frate-limiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AfterShip%2Frate-limiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AfterShip%2Frate-limiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AfterShip","download_url":"https://codeload.github.com/AfterShip/rate-limiter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248802329,"owners_count":21163825,"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-11-15T21:27:09.179Z","updated_at":"2025-04-14T00:35:33.673Z","avatar_url":"https://github.com/AfterShip.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rate-limiter\n\n[![Build Status](https://travis-ci.org/AfterShip/rate-limiter.svg?branch=master)](https://travis-ci.org/AfterShip/rate-limiter)\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FAfterShip%2Frate-limiter.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FAfterShip%2Frate-limiter?ref=badge_shield)\n\n[![node](https://img.shields.io/node/v/@aftership/rate-limiter.svg)]()\n[![npm](https://img.shields.io/npm/v/@aftership/rate-limiter.svg)]()\n[![npm](https://img.shields.io/npm/dm/@aftership/rate-limiter.svg)]()\n\n\nRate limit for Node.js, with ioredis client\n\n## Installation\n\n```\nnpm install @aftership/rate-limiter\n```\n\n## Dependency\nThe client must be an instance of `ioredis` library.\n\n## Examples\n\n```javascript\nconst Limiter = require('@aftership/rate-limiter');\nconst Redis = require('ioredis');\n\nconst redisClient = new Redis({\n\tport: 6379,\n\thost: '127.0.0.1',\n\tdb: 0\n});\n\nredisClient.on('connect', (err) =\u003e {\n\tif (err) {\n\t\tconsole.log(err);\n\t\treturn;\n\t}\n\n\t// limit to 2 request per every 10s\n\tconst limiter = new Limiter({\n\t\tredisClient,\n\t\tkey: 'the-user-api-key',\n\t\tlimit: 2, // default is 10\n\t\tduration: 10 // default is 60s\n\t});\n\n\tlimiter\n\t\t.get()\n\t\t.then((result) =\u003e {\n\t\t\tconsole.log(result);\n\n\t\t\tif (result.remaining \u003e= 0) {\n\t\t\t\tconsole.log('I can do the request!');\n\t\t\t} else {\n\t\t\t\tconsole.log(`I run out of limit! Try again after ${result.reset} second.`);\n\t\t\t}\n\t\t\tprocess.exit(0);\n\t\t})\n\t\t.catch((e) =\u003e {\n\t\t\tconsole.log(e);\n\t\t});\n});\n\n```\n\n## Change log\n\nPlease refer to release page\n\n\n## License\nCopyright (c) 2019 AfterShip\n\nLicensed under the MIT license.\n\n\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FAfterShip%2Frate-limiter.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FAfterShip%2Frate-limiter?ref=badge_large)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faftership%2Frate-limiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faftership%2Frate-limiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faftership%2Frate-limiter/lists"}