# ip-rate-limiter

> A rate-limiter inspired by Dcard's backend developer intern homework.

Latest version **1.0.1** (published 2020-06-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install ip-rate-limiter
pnpm add ip-rate-limiter
yarn add ip-rate-limiter
bun add ip-rate-limiter
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-06-21 |
| First published | 2020-06-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 18.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Kyle Mo |
| Maintainers | oldmo860617 |
| Keywords | rate-limiter |

## Links

- npm: https://www.npmjs.com/package/ip-rate-limiter
- npm.io page: https://npm.io/package/ip-rate-limiter

## Dependencies (3)

- [redis](https://npm.io/package/redis.md) ^3.0.2
- [express](https://npm.io/package/express.md) ^4.17.1
- [body-parser](https://npm.io/package/body-parser.md) ^1.19.0

## Recent versions

- 1.0.1 (latest) — 2020-06-21
- 1.0.0 — 2020-06-21

## README

# ip-rate-limiter
> An expressJS ip-rate-limit middleware built with TypeScript which inspired by Dcard's internship program.

[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![Weekly Downloads](https://img.shields.io/npm/dw/koa-grounded)](https://img.shields.io/npm/dw/ip-rate-limiter)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fkylemocode%2Fnodejs-rate-limiter.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fkylemocode%2Fnodejs-rate-limiter?ref=badge_shield)

## 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

## license

[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fkylemocode%2Fnodejs-rate-limiter.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fkylemocode%2Fnodejs-rate-limiter?ref=badge_large)

---
_Source: https://npm.io/package/ip-rate-limiter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
