Skip to content

Instantly share code, notes, and snippets.

@petrosDemetrakopoulos
Created January 19, 2021 08:13
Show Gist options
  • Save petrosDemetrakopoulos/e62f4b11259af7dfb9630ddbf68c6c18 to your computer and use it in GitHub Desktop.
Save petrosDemetrakopoulos/e62f4b11259af7dfb9630ddbf68c6c18 to your computer and use it in GitHub Desktop.
var rateLimit = require("express-rate-limit");
app.set('trust proxy', 1); // add this line only if your server is behind a proxy
var limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // limit each IP to 100 requests per windowMs
delayMs: 0 // disable delaying - user has full speed until the max limit is reached
});
app.use(limiter); // applies rate limiting policy to every endpoint of the server
// we could also apply policies for specific routes or even different policies for each route
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment