# guy-rate-limiter

> A distrebuted Rate Limiter Allowing each user to perform up to 500 requests in a 60 seconds time frame.

Latest version **1.0.3** (published 2020-01-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install guy-rate-limiter
pnpm add guy-rate-limiter
yarn add guy-rate-limiter
bun add guy-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.3 |
| Published | 2020-01-04 |
| First published | 2020-01-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 7.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Guy Hardonag |
| Maintainers | ghardonag |

## Links

- npm: https://www.npmjs.com/package/guy-rate-limiter
- Repository: https://github.com/ghardonag/guy_rate_limit_public
- Homepage: git://github.com/ghardonag/guy_rate_limit_public
- Issues: https://github.com/ghardonag/guy_rate_limit_public/issues
- npm.io page: https://npm.io/package/guy-rate-limiter

## Dependencies (2)

- [redis](https://npm.io/package/redis.md) ^2.8.0
- [microtime](https://npm.io/package/microtime.md) ^3.0.0

## Recent versions

- 1.0.3 (latest) — 2020-01-04
- 1.0.2 — 2020-01-04
- 1.0.1 — 2020-01-04
- 1.0.0 — 2020-01-04

## README

# guy-rate-limiter

A distrebuted Rate Limiter Allowing each user to perform up to 500 requests in a 60 seconds time frame.

## Install
```sh
$ npm install --save guy-rate-limiter
```

## Configuration

The Default Rate Limiter Redis Configuration uses:
host = 127.0.0.1
port = 6379

To Change it set the environment variables:

RATE_LIMIT_REDIS_PORT

RATE_LIMIT_REDIS_HOST

By running: 

```sh
$ export RATE_LIMIT_REDIS_PORT=[REDIS_PORT]
$ export RATE_LIMIT_REDIS_HOST=[REDIS_HOST]
```
Or in any other way

## USAGE EXAMPLE

export RATE_LIMIT_REDIS_PORT=6378
There are two options to use:

1. use as an express middleware 

```js
const express = require('express')
const rateLimiter = require('guy-rate-limiter');
const app = express();
const port = 3000;

app.use((req, res, next) => {
  req.userID = req.query.uid || 'UNKNOWN'; 
  next();
});
const rateLimitMiddleware = rateLimiter.getExpressMiddleware('ip');
app.use(rateLimitMiddleware);
app.get('/', function (req, res) {
  res.send(`Hello ${req.userID}`);
});

 
app.listen(port)
```


2. use only the rate limitter

```js
const rateLimiter = require('guy-rate-limiter');

rateLimiter.handleUserRequest(userId,(err,allow) => {
      if(err) {
        //handle error
      }
      else if (!allow){
        //handle block
      }
      else {
        //handle allow
      }
  });
```

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