Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including express-redis-limit-req with all npm packages installed. Try it out:

var expressRedisLimitReq = require("express-redis-limit-req")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

express-redis-limit-req v1.0.4

Basic rate-limiting middleware for Express. Use to limit repeated requests to public APIs and/or endpoints.

Express Redis Rate Limit

Basic rate-limiting middleware for Express using Redis. Use to limit repeated requests to public APIs and/or endpoints.

Installation

$ npm install express-redis-limit-req

Usage

const RateLimit = require("express-redis-limit-req");
const limiter = RateLimit({
  redisURL: "redis://127.0.0.1:6379", // redis connection url
  expiration: 3600, // 1 hour
  max: 10, // limit each IP to 10 requests per expiration
  message: "Too many requests.", // Message that should be sent back to the user, Default is Too many request
  statusCode: 429, // Status code to be returned. Default is 429
  whiteList: [192.168.1.1, 192.168.1.2] // Whitelist IP address for unlimited requests
})

// apply to all requests
app.use(limiter)

Configuration

  • redisURL: Redis connection URL
  • expiration: second - how long each rate limiting IP address exists for
  • max: Max number of connections during expiration before sending a 429 response.
  • message: Error message sent to user when max is exceeded. Defaults to 'Too many requests.'
  • statusCode: HTTP status code returned when max is exceeded. Defaults to 429.
  • whiteList: WhiteList some specified IP address for unlimited requests.

License

MIT © Olohundare Nasirudeen https://github.com/iamnasirudeen

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free