throttle-titan-middleware
v1.0.0
Published
A simple and lightweight rate limiter middleware
Downloads
5
Maintainers
Readme
Throttle Titan Middleware
A lightweight and type-safe rate limiting middleware for Express applications.
Installation
npm install throttle-titan-middlewareUsage
import { createRateLimitMiddleware } from 'throttle-titan-middleware';
// Create the middleware with your desired configuration
const rateLimitMiddleware = createRateLimitMiddleware({
windowMs: 1000, // Time window in milliseconds
limit: 30 // Maximum requests allowed per window
});
// Apply globally to all routes
app.use(rateLimitMiddleware);
// Or apply to specific routes
app.get('/api/sensitive', rateLimitMiddleware, (req, res) => {
// Your route handler
});Configuration Options
| Option | Type | Description | |----------|---------|-------------------------------------------| | windowMs | number | The time window in milliseconds | | limit | number | Maximum number of requests allowed per window |
Response
When the rate limit is exceeded, the middleware returns:
{
"error": "Rate limit exceeded"
}with HTTP status code 429 (Too Many Requests)
License
MIT
