An open API service indexing awesome lists of open source software.

https://github.com/0xradioac7iv/rate-limiter

Rate Limiting Middleware Library for Express & Fastify
https://github.com/0xradioac7iv/rate-limiter

express fastify fastify-plugin nodejs npm npm-package rate-limiter rate-limiting

Last synced: 12 months ago
JSON representation

Rate Limiting Middleware Library for Express & Fastify

Awesome Lists containing this project

README

          

# Rate Limiter ๐Ÿš€

A lightweight and efficient rate-limiting library for Node.js, designed to help developers control API request rates and prevent abuse.

## Features

- โœ… In-memory, Redis & Mongo Support
- โœ… Dynamic Rate Limiting
- โœ… Supports Express, Fastify & NestJS

## Setup

### Installation

```bash
npm install @radioac7iv/rate-limiter
```

### Usage

Basic example using Express:

```typescript
import express from "express";
import { expressRateLimiter } from "@radioac7iv/rate-limiter";

const app = express();

const rateLimit = expressRateLimiter({
limitOptions: () => {
return { max: 5, window: 10 };
},
});

app.use(rateLimit);

app.get("/", (request, response) => {
response.status(200).send({ message: "Hello!" });
});

app.listen(3000, () => {
console.log("Server started at PORT: 3000");
});
```

### ๐Ÿ“– Documentation

Detailed usage, configuration options, and examples are available in the official documentation:

[Read the Docs](https://rate-limiter.0xradioactiv.xyz/)

### ๐Ÿค Contributing

Contributions are welcome! To get started:

1. Fork the repository
2. Clone your fork

3. Install dependencies:

```bash
npm install
```

4. Create a new branch:

```bash
git checkout -b feature-name
```

5. Make your changes & commit:

```bash
git commit -m "Add new feature"
```

6. Push & open a PR:

```bash
git push origin feature-name
```

Read the full Contribution Guidelines [here](./CONTRIBUTING.md)

### ๐Ÿงช Testing

To run the tests:

```bash
cd package
npm test
```

To get coverage report:

```bash
npm run test:cov
```

### ๐Ÿ“œ License

This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.