A. Incorrect import statement for express-rate-limit
B. Missing windowMs option to define the time window
C. Using max instead of limit option
D. Calling app.use before defining limiter
Solution
Step 1: Check required options for rateLimit
The windowMs option is needed to specify the time frame for the limit.
Step 2: Identify missing option
The code only sets max but does not set windowMs, so the time window is undefined.
Final Answer:
Missing windowMs option to define the time window -> Option B
Quick Check:
windowMs missing = A [OK]
Hint: Always set windowMs with max for rateLimit [OK]
Common Mistakes:
Forgetting windowMs causes no time limit
Confusing max with limit option
Wrong import syntax
5. You want to apply rate limiting only to the login route to prevent brute force attacks. Which code snippet correctly applies express-rate-limit only to /login?
hard
A. app.use('/login', rateLimit({ windowMs: 60000, max: 5 }));
B. app.use(rateLimit({ windowMs: 60000, max: 5 })); app.use('/login');
C. app.get('/login', rateLimit({ windowMs: 60000, max: 5 }));
D. app.post(rateLimit({ windowMs: 60000, max: 5 }), '/login');
Solution
Step 1: Understand how to apply middleware to specific routes
Using app.use('/login', middleware) applies the middleware only to the /login path.
Step 2: Check the correct syntax for rateLimit middleware
Calling rateLimit with options returns middleware to pass to app.use.
Final Answer:
app.use('/login', rateLimit({ windowMs: 60000, max: 5 })); -> Option A
Quick Check:
Middleware on route = A [OK]
Hint: Use app.use with path and rateLimit middleware [OK]
Common Mistakes:
Calling app.use without path for specific routes
Using app.get or app.post incorrectly with middleware
Passing middleware after route string
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.