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

https://github.com/muradisazade777/ts-rate-limiter

A modular, scalable, and production-ready API rate limiter built with TypeScript and Redis. Designed for Express and Fastify, this package provides plug-and-play middleware, CLI tools, and branded configuration for managing request limits across endpoints and IPs.
https://github.com/muradisazade777/ts-rate-limiter

api backend backend-api config configuration javascript js json redis testing token ts typescript

Last synced: 9 months ago
JSON representation

A modular, scalable, and production-ready API rate limiter built with TypeScript and Redis. Designed for Express and Fastify, this package provides plug-and-play middleware, CLI tools, and branded configuration for managing request limits across endpoints and IPs.

Awesome Lists containing this project

README

          

# ๐Ÿšฆ TS Rate Limiter

A modular, scalable, and production-ready API rate limiter built with TypeScript and Redis. Designed for Express and Fastify, this package provides plug-and-play middleware, CLI tools, and branded configuration for managing request limits across endpoints and IPs.

---

## โœจ Features

- ๐Ÿ”ง Token Bucket / Sliding Window algorithm
- ๐Ÿง  Redis-based usage tracking
- ๐Ÿงฉ Express & Fastify middleware support
- ๐Ÿ› ๏ธ CLI tools for stats and reset
- ๐Ÿ“ฆ Modular architecture with clean separation of concerns
- ๐Ÿ“Š Configurable via JSON or YAML
- ๐Ÿงช Fully tested with Jest

---

## ๐Ÿ“ฆ Installation

```bash
npm install ts-rate-limiter
```

## ๐Ÿš€ Usage

### Express Integration

```ts
import express from 'express';
import { expressLimiter } from 'ts-rate-limiter';
import { RateLimiter, RedisAdapter, loadConfig } from 'ts-rate-limiter';

const app = express();
const config = loadConfig();
const adapter = new RedisAdapter(process.env.REDIS_URL || 'redis://localhost:6379');
const limiter = new RateLimiter(config, adapter);

app.use(expressLimiter(limiter));
app.get('/api', (req, res) => res
```

CLI Commands
```bash
# Show usage stats
npm run cli stats 127.0.0.1:/api

# Reset usage for a key
npm run cli reset 127.0.0.1:/api
```
๐Ÿงช Testing
```bash
npm test
```

Each folder is modular and purpose-driven:

- **core/** โ€“ Implements the rate limiting logic and exposes the public API.
- **adapters/** โ€“ Contains pluggable storage backends (e.g., Redis, in-memory).
- **middleware/** โ€“ Provides ready-to-use integrations for Express and Fastify.
- **config/** โ€“ Loads default configurations and limit presets.
- **cli/** โ€“ CLI interface with commands and branding banner.
- **utils/** โ€“ Shared utilities like logging and time calculations.
- **tests/** โ€“ Comprehensive Jest test coverage for all modules.

๐Ÿ“œ License
This project is licensed under the MIT License. See the LICENSE file for details.

๐Ÿ’ก Author
Murad โ€” Backend Architect & Full Stack Developer Crafted with precision, modularity, and branded elegance โœจ