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.
- Host: GitHub
- URL: https://github.com/muradisazade777/ts-rate-limiter
- Owner: MuradIsazade777
- License: other
- Created: 2025-11-06T15:55:29.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-11-06T16:24:52.000Z (9 months ago)
- Last Synced: 2025-11-06T18:16:56.600Z (9 months ago)
- Topics: api, backend, backend-api, config, configuration, javascript, js, json, redis, testing, token, ts, typescript
- Language: TypeScript
- Homepage:
- Size: 13.9 MB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 โจ