Rate Limiter Setup
Which middleware is most commonly used in Express.js to implement rate limiting on a per-user basis?
- A. express-session
- B. cors
- C. express-rate-limit
- D. body-parser
- E. morgan
Identifying Users
How can you reliably identify a user for rate limiting purposes in an Express.js application?
- A. By their IP address only, using `req.ip`
- B. Only by their username
- C. By their browser's user agent
- D. By a combination of IP address and user ID (if authenticated) or a session identifier
- E. Randomly assigning a number to each request.
Rate Limit Store
What is the purpose of a 'store' in the `express-rate-limit` middleware?
- A. To store user session data.
- B. To temporarily cache the requested jokes.
- C. To store the rate limit counters for each user.
- D. To store API keys.
- E. To store the configuration settings for the rate limiter.
Custom Key Generator
You want to use the user ID from a JWT (JSON Web Token) for rate limiting. How would you customize the `keyGenerator` option in `express-rate-limit`?
- A. Set `keyGenerator` to `'req.user.id'`.
- B. `keyGenerator: (req, res) =u003E req.headers['user-id'];`
- C. `keyGenerator: (req) =u003E req.user.id;` if `req.user` is populated by a JWT middleware.
- D. By not including a keyGenerator at all.
- E. Setting the store to the user's ID.
Rate Limit Exceeded Response
What HTTP status code should your server typically return when a user exceeds the rate limit?
- A. 200 OK
- B. 400 Bad Request
- C. 404 Not Found
- D. 429 Too Many Requests
- E. 500 Internal Server Error
Time Window Configuration
How do you configure the duration of the rate limiting 'window' using `express-rate-limit`?
- A. Using the `window` option in milliseconds.
- B. Using the `duration` option in seconds.
- C. Using the `timeframe` property in minutes.
- D. Using the `windowMs` option in milliseconds.
- E. This feature cannot be configured.
Max Requests Configuration
How do you specify the maximum number of requests allowed within the defined time window using `express-rate-limit`?
- A. Using the `requests` property.
- B. Using the `limit` property.
- C. Using the `max` option.
- D. Using the `allowedRequests` option.
- E. This feature is defined by the underlying store.
Custom Error Message
How can you customize the error message returned when a user exceeds the rate limit?
- A. Using the `errorMessage` option.
- B. Using the `message` option and passing a string.
- C. By modifying the HTTP status code.
- D. You cannot customize the message
- E. Using the `error` property and passing a function.
Ignoring specific routes
You want to exclude a specific route, '/healthcheck', from rate limiting. How do you achieve this with `express-rate-limit`?
- A. Wrap the route handler in a `noRateLimit` function.
- B. Use the `skip` option with a function that returns true for '/healthcheck'.
- C. You cannot exclude specific routes.
- D. Set `max` to 0 for the '/healthcheck' route.
- E. By setting `windowMs` to 0 on that route
In-Memory Store Limitations
What is a major limitation of using the default in-memory store provided by `express-rate-limit` in a production environment?
- A. It is incredibly slow.
- B. It does not support HTTPS.
- C. It will only store IP addresses.
- D. It doesn't work with cookies.
- E. It does not scale horizontally across multiple server instances.