Package: npm install –save rate-limit-mongo
ROUTE:
routes.get(
"/example",
general, // This is my rate limit
(req, res) => {
return res.status(201).end()
}
)
MIDDLEWARE:
module.exports.general = new RateLimit({
store: new MongoStore({
uri: process.env.MONGODB_CNN + "api-limiter",
expireTimeMs: 15 * 60 * 1000,
errorHandler: console.error.bind(null, 'rate-limit-mongo'),
collectionName: "general",
}),
max: 50,
windowMs: 15 * 60 * 1000,
skipSuccessfulRequests: true
});
Thank you in advance