Express.js Redis API Rate Limiting & DDoS Prevention
Production Express.js middleware using rate-limiter-flexible and ioredis. Implements dual-tier rate limiting (burst protection + long-term quota limit), IP spoofing validation, and customized JSON error responses.
Appended directly to the LLM system prompt for tailored code output.
Generated Code
⚡ Instant Boilerplate| 1 | const { RateLimiterRedis } = require('rate-limiter-flexible'); |
| 2 | const Redis = require('ioredis'); |
| 3 | const redisClient = new Redis(process.env.REDIS_URL || 'redis://localhost:6379'); |
| 4 | const rateLimiter = new RateLimiterRedis({ storeClient: redisClient, points: 60, duration: 60 }); |
| 5 | |
| 6 | const rateLimitMiddleware = async (req, res, next) => { |
| 7 | try { |
| 8 | await rateLimiter.consume(req.ip); |
| 9 | next(); |
| 10 | } catch (err) { |
| 11 | res.status(429).json({ error: 'Too Many Requests' }); |
| 12 | } |
| 13 | }; |
| 14 | module.exports = { rateLimitMiddleware }; |
| 15 |
Deploy this boilerplate automatically in 1 click.
Related Generators
View AllExpress.js Secure HttpOnly Cookie JWT & Refresh Token Auth
Secure Node.js Express authentication API storing JWT refresh tokens inside HttpOnly, SameSite=Strict cookies to eliminate XSS token theft.
FastAPIFastAPI JWT Authentication & Refresh Token Rotation
Production-grade FastAPI auth middleware featuring Argon2id password hashing, JWT access/refresh token rotation, and dependency injection guard.
Next.jsNext.js App Router Auth.js (NextAuth v5) Credentials & OAuth
Complete Auth.js (NextAuth v5) authentication configuration for Next.js App Router with JWT session strategy, credentials provider, and middleware route protection.