Complete the code to import the rate limiting middleware from the 'express-rate-limit' package.
const rateLimit = require('[1]');
The correct package name to import the rate limiting middleware is express-rate-limit.
Complete the code to create a rate limiter that allows 100 requests per 15 minutes.
const limiter = rateLimit({ windowMs: [1], max: 100 });The windowMs option is in milliseconds. 15 minutes equals 900,000 milliseconds.
Fix the error in applying the rate limiter middleware to an Express app.
app.[1](limiter);app.apply() or app.run() which do not exist.app.listen() to add middleware.In Express, middleware is added using the use method.
Fill both blanks to create a rate limiter that sends a custom message when the limit is exceeded.
const limiter = rateLimit({ windowMs: 60000, max: 10, message: '[1]', statusCode: [2] });The message option sets the response text, and statusCode should be 429 for too many requests.
Fill all three blanks to create a rate limiter that uses a custom key generator and skips requests from localhost.
const limiter = rateLimit({ windowMs: 60000, max: 5, keyGenerator: (req) => req.[1], skip: (req) => req.[2] === '[3]' });req.hostname, which is the requested hostname from the Host header, not the client IP.req.url instead of IP for skipping.The keyGenerator uses req.ip to identify clients. The skip function checks if req.ip equals 127.0.0.1 to skip rate limiting.