https://github.com/kylemocode/nodejs-rate-limiter
https://github.com/kylemocode/nodejs-rate-limiter
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/kylemocode/nodejs-rate-limiter
- Owner: kylemocode
- Created: 2020-03-08T16:24:07.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-12T04:33:17.000Z (over 3 years ago)
- Last Synced: 2025-03-29T05:51:10.155Z (about 1 year ago)
- Language: TypeScript
- Size: 7.68 MB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ip-rate-limiter
> An expressJS ip-rate-limit middleware built with TypeScript which inspired by Dcard's internship program.
[](https://github.com/prettier/prettier)
[](https://img.shields.io/npm/dw/ip-rate-limiter)
## Requirements
- [X] 限制每小時來自同一個 IP 的請求數量不得超過 1000
- [X] 在 response headers 中加入剩餘的請求數量 (X-RateLimit-Remaining) 以及 rate limit 歸零的時間 (X-RateLimit-Reset)
- [X] 如果超過限制的話就回傳 429 (Too Many Requests)
- [X] 使用 TypeScript + express + redis 完成
## Quick Start
### Install
```shell
$ npm install ip-rate-limiter
```
### Basic Usage
```TypeScript
import express, { Application, Request, Response, NextFunction } from 'express';
import rateLimiter from 'ip-rate-limiter';
import bodyParser from 'body-parser';
const app: Application = express();
app.use(bodyParser.json());
app.get('/', rateLimiter, (req: Request, res: Response) => {
res.send('test');
})
app.listen(5000, () => {
console.log('server running on port 5000');
})
```
## Roadmap
- [ ] Flexible arguments
- [ ] Increase Unit Test Coverage
- [ ] Support for other Redis Client