Complete the code to import the express-rate-limit package.
const rateLimit = require('[1]');
The package name to import for rate limiting in Express is express-rate-limit.
Complete the code to create a rate limiter that allows 100 requests per 15 minutes.
const limiter = rateLimit({ windowMs: 15 * 60 * 1000, max: [1] });The max option sets the maximum number of requests allowed. Here, it should be 100.
Fix the error in applying the rate limiter middleware to all routes.
app.use([1]);The rate limiter is a middleware function stored in limiter. It should be passed directly without calling it.
Fill both blanks to create a rate limiter that sends a custom message when limit is exceeded.
const limiter = rateLimit({ windowMs: 10 * 60 * 1000, max: 50, [1]: (req, res) => { res.status(429).send([2]); } });The handler option defines a function to run when the limit is exceeded. The message is sent as a string in the response.
Fill all three blanks to create a rate limiter with a 5-minute window, max 20 requests, and a custom message.
const limiter = rateLimit({ windowMs: [1] * 60 * 1000, max: [2], handler: (req, res) => { res.status(429).send([3]); } });The windowMs is set to 5 minutes (5 * 60 * 1000 ms), max requests is 20, and the handler sends a custom message string.