NodeJsRate Limiting

Rate limiting prevents abuse of APIs by restricting the number of requests a client can make within a certain timeframe. It's essential for protecting your server from overload or malicious attacks.

npm install express-rate-limit

const rateLimit = require('express-rate-limit');
const express = require('express');
const app = express();

const limiter = rateLimit({
  windowMs: 1 * 60 * 1000, // 1 minute
  max: 5 // limit each IP to 5 requests per minute
});

app.use(limiter);
app.get('/', (req, res) => res.send('Hello, Rate Limit!'));

app.listen(3000);