express-rate-limit nodejs

// Step 1: Install express-rate-limit package
npm install express-rate-limit

// Step 2: Require the express-rate-limit module in your Node.js file
const rateLimit = require('express-rate-limit');

// Step 3: Define the rate limiter middleware with desired options
const limiter = rateLimit({
  windowMs: 15  60  1000, // 15 minutes
  max: 100, // limit each IP to 100 requests per windowMs
  message: 'Too many requests from this IP, please try again after some time.'
});

// Step 4: Apply the rate limiter middleware to your Express application
app.use(limiter);

// Step 5: Handle requests in your route or middleware as usual
app.get('/example', (req, res) => {
  res.send('This route is rate-limited.');
});

Note: Make sure to adjust the windowMs and max values based on your specific requirements. The windowMs defines the time frame for which the rate limiting is applied, and max specifies the maximum number of requests allowed from a single IP within that time frame.