Intermediate LevelExpress JS
How does the express-slow-down middleware throttle abusive requests by delaying responses?
❓ Interview Prompt: Explain response throttling with express-slow-down, progressive artificial delay insertion, and graceful web scraper deterrence.
Instead of blocking abusive requests with '429 Too Many Requests', 'express-slow-down' applies progressive artificial delay to responses.
How Throttling Works:
Allows a threshold of fast requests (e.g. 50 requests). After 50 requests, every subsequent request is delayed by an increasing millisecond penalty (500ms, 1000ms, 1500ms), gently deterring web scrapers without breaking user experience!
Code Implementation Example
javascript
import express from 'express';
import slowDown from 'express-slow-down';
const app = express();
const speedLimiter = slowDown({
windowMs: 15 * 60 * 1000, // 15 minutes
delayAfter: 50, // Allow 50 requests at full speed
delayMs: (hits) => (hits - 50) * 500 // Add 500ms delay per hit above 50!
});
app.use('/api/', speedLimiter);💡Progressively throttling abusive API traffic using express-slow-down.
🎯 Interview Key Takeaway
Use express-slow-down to progressively delay responses for abusive clients without returning immediate 429 errors.
#express-slow-down#Throttling#Rate Limiting#Intermediate
Back to all Express JS Questions→