6. JavaScript: Advanced Rate Limiter
Node.jsMiddleware that protects endpoints from DDoS and brute-force attacks.
const rateLimit = require('express-rate-limit');
const apiLimiter = rateLimit({
windowMs: 15 * 60 * 1000,
max: 100,
standardHeaders: true,
legacyHeaders: false,
message: { status: 429, error: "Zbyt wiele żądań, spróbuj później." }
});
When to use
Use it on public API endpoints to cap the number of requests from a single IP address within a given time window.
Common pitfalls
The default rate limiter works in process memory — with multiple server instances each counts limits separately; a shared store (e.g. Redis) is required.