Back to course

Rate Limiting

How to do that?

Well,

  1. Limit the number of requests a client can make within a timeframe.
  2. Configure adaptive rate limiting based on user behavior or IP reputation.
  3. Ensure your rate limiting strategy does not lock out legitimate users.

Example:

const rateLimit = require('express-rate-limit');
const apiLimiter = rateLimit({
  windowMs: 15 * 60 * 1000, // 15 minutes
  limit: 100 // limit each IP to 100 requests per windowMs
});
app.use('/api/', apiLimiter);

Want to learn more? Check out the OWASP Rate Limiting Cheat Sheet