What is rate limiting, and how can you implement it in Node.js?

Rate limiting controls how often a user can make requests to an API, preventing abuse. Libraries like express-rate-limit can be used for this purpose:

const rateLimit = require('express-rate-limit');
const limiter = rateLimit({
  windowMs: 15 * 60 * 1000, // 15 minutes
  max: 100 // Limit each IP to 100 requests per windowMs
});

app.use(limiter); // Apply rate limiting to all requests