# koa-rate-limiter

> A Redis-based middleware designed for Koa2

Latest version **1.1.0** (published 2017-05-16) · ISC license · 0 weekly downloads

## Install

```sh
npm install koa-rate-limiter
pnpm add koa-rate-limiter
yarn add koa-rate-limiter
bun add koa-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.1.0 |
| Published | 2017-05-16 |
| First published | 2017-05-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | WithGJR |
| Maintainers | kevin3372000 |

## Links

- npm: https://www.npmjs.com/package/koa-rate-limiter
- Repository: https://github.com/WithGJR/rate-limiter
- Homepage: https://github.com/WithGJR/rate-limiter#readme
- Issues: https://github.com/WithGJR/rate-limiter/issues
- npm.io page: https://npm.io/package/koa-rate-limiter

## Recent versions

- 1.1.0 (latest) — 2017-05-16
- 1.0.0 — 2017-05-16

## README

# Rate Limiter

A rate limit middleware designed for Koa2.

## Installation

`npm install koa-rate-limiter --save`

## Usage

```javascript
const Koa = require('koa');
const Redis = require('ioredis');
const redis = new Redis();
const app = new Koa();
const ratelimit = require('koa-rate-limiter');

app.use(ratelimit({
    db: redis,
    max: 1000
}));

app.use((ctx, next) => {
    ctx.body = "hello";
});

app.listen(3000);
console.log('listening on port 3000');
```
### Available Options

1. `db`: A redis connection instance
2. `max`: Max request number per visitor(more precisely, an IP address) every hour

## Response Headers

Everytime a HTTP request comes in, two response headers will be set:

1. X-RateLimit-Remaining: Indicate how many HTTP requests a visitor can send before the limit is reached.
2. X-RateLimit-Reset: Indicate remaining time to next hour (in millisecond). In other word, when will the count be reset again.

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