Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the purpose of rate limiting in an Express app?
Rate limiting helps protect your app by limiting how many requests a user can make in a set time. It stops overload and abuse, like too many requests from one user.
Click to reveal answer
beginner
How do you add express-rate-limit middleware to an Express app?
You first install express-rate-limit, then import it. Create a limiter with options like max requests and window time. Use app.use() to apply it to routes.
Click to reveal answer
beginner
What does the 'windowMs' option control in express-rate-limit?
It sets the time window in milliseconds for counting requests. For example, 60000 means requests are counted per minute.
Click to reveal answer
beginner
What happens when a user exceeds the max number of requests in express-rate-limit?
The user gets a 429 status code (Too Many Requests) and a message telling them to slow down.
Click to reveal answer
intermediate
How can you customize the message sent when rate limit is exceeded?
You can use the 'handler' option in express-rate-limit to define a custom function that sends your own message or response.
Click to reveal answer
What package do you use to add rate limiting in an Express app?
Aexpress-rate-limit
Bexpress-session
Ccors
Dbody-parser
✗ Incorrect
express-rate-limit is the package designed to limit repeated requests to Express routes.
Which option sets the max number of requests allowed in express-rate-limit?
AwindowMs
Bmax
CdelayMs
Dhandler
✗ Incorrect
'max' defines the maximum number of requests allowed during the time window.
What HTTP status code does express-rate-limit send when limit is exceeded?
A403 Forbidden
B401 Unauthorized
C429 Too Many Requests
D500 Internal Server Error
✗ Incorrect
429 status code means the user sent too many requests in a given time.
How do you apply rate limiting to all routes in an Express app?
AUse app.use() with the limiter middleware
BAdd limiter inside each route handler
CSet limiter in package.json
DUse a global variable
✗ Incorrect
app.use(limiter) applies the rate limiter middleware to all routes.
Which option lets you customize the response when rate limit is hit?
Askip
BwindowMs
Cmax
Dhandler
✗ Incorrect
'handler' is a function you provide to send a custom response when the limit is exceeded.
Explain how to set up express-rate-limit in a new Express app to limit requests to 100 per 15 minutes.
Think about the steps from installing to applying middleware.
You got /4 concepts.
Describe what happens when a user sends too many requests and how express-rate-limit handles it.
Focus on the user experience and server response.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of using express-rate-limit in an Express app?
easy
A. To handle database connections efficiently
B. To speed up the server response time
C. To automatically restart the server on code changes
D. To limit the number of requests a user can make in a time window
Solution
Step 1: Understand the purpose of rate limiting
Rate limiting is used to protect the server by restricting how many requests a user can send in a short time.
Step 2: Identify what express-rate-limit does
This package helps set these limits easily in Express apps.
Final Answer:
To limit the number of requests a user can make in a time window -> Option D
Quick Check:
Rate limiting = limit requests [OK]
Hint: Rate limiting controls request count per time window [OK]
Common Mistakes:
Thinking it speeds up server responses
Confusing it with server restart tools
Assuming it manages database connections
2. Which of the following is the correct way to import and use express-rate-limit in an Express app?
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