# micro-ratelimit

> Rate-limiting middleware for micro

Latest version **0.4.0** (published 2018-10-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install micro-ratelimit
pnpm add micro-ratelimit
yarn add micro-ratelimit
bun add micro-ratelimit
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2018-10-04 |
| First published | 2017-03-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.2.1 |
| Dependencies | 0 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 73 |
| Author | Vitaly Domnikov |
| Maintainers | dotcypress |
| Keywords | rate limit, micro, microservices, middleware |

## Links

- npm: https://www.npmjs.com/package/micro-ratelimit
- Repository: https://github.com/dotcypress/micro-ratelimit
- Homepage: https://github.com/dotcypress/micro-ratelimit#readme
- Issues: https://github.com/dotcypress/micro-ratelimit/issues
- npm.io page: https://npm.io/package/micro-ratelimit

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.4.0 (latest) — 2018-10-04
- 0.3.0 — 2017-09-21
- 0.2.0 — 2017-04-08
- 0.1.0 — 2017-03-30
- 0.0.1 — 2017-03-30

## README

[![Build Status](https://img.shields.io/travis/dotcypress/micro-ratelimit.svg?branch=master&style=flat-square)](https://travis-ci.org/dotcypress/micro-ratelimit)
[![NPM Version](https://img.shields.io/npm/v/micro-ratelimit.svg?style=flat-square)](https://www.npmjs.com/package/micro-ratelimit)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/)

# Micro Rate Limit

Rate-limiting middleware for [micro](https://github.com/zeit/micro).

## Installation

```js
$ npm install micro-ratelimit
```

## Examples
  
```js
const rateLimit = require('micro-ratelimit')

module.exports = rateLimit((req, res) => {
  return 'Hello world'
})

```

```js
const rateLimit = require('micro-ratelimit')

// Limit example: 2 requests per 10 sec
module.exports = rateLimit({ window: 10000, limit: 2, headers: true }, (req, res) => {
  return 'Hello world'
})

```

## API

### Options

* `window`: how long to keep records of requests in memory in ms (default: 1 second)
* `limit`: max number of requests during window (default: 1)
* `keyGenerator`: key generator function (req -> client id)
* `headers`: send rate limit headers (default: false)

Default implementation of `keyGenerator`:

```js
function keyGenerator (req) {
  return req.headers['x-forwarded-for'] ||
    req.connection.remoteAddress ||
    req.socket.remoteAddress ||
    req.connection.socket.remoteAddress
}
```

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