Express rate-limiter
Rate limiting middleware for Express applications built on redis
npm install express-limiter --save
var express =var app =var client =var limiter = app client/*** you may also pass it an Express 4.0 `Router`** router = express.Router()* limiter = require('express-limiter')(router, client)*/app
API options
path:Stringoptional route path to the requestmethod:Stringoptional http method. acceptsget,post,put,delete, and of course Express'alllookup:Function|String|Array.<String>value lookup on the request object. Can be a single value, array or function. See examples for common usagestotal:Numberallowed number of requests before getting rate limitedexpire:Numberamount of time inmsbefore the rate-limited is resetwhitelist:function(req)optional param allowing the ability to whitelist. returnboolean,trueto whitelist,falseto passthru to limiter.skipHeaders:Booleanwhether to skip sending HTTP headers for rate limits ()ignoreErrors:Booleanwhether errors generated from redis should allow the middleware to call next(). Defaults to false.onRateLimited:Functioncalled when a request exceeds the configured rate limit.
Examples
// limit by IP address// or if you are behind a trusted proxy (like nginx)// by user (assuming a user is logged in with a valid id)// limit your entire app// limit users on same IP// whitelist user admins// skip sending HTTP limit headers// call a custom limit handler// with a function for dynamic-ness
as direct middleware
app
License MIT
Happy Rate Limiting!