Skip to content

lyhper/node-rate-limit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-rate-limit

A simple rate-limiting express middleware acoording to IP address

About

It uses built-in memory cache by default, and you can use your own redis cache. No matter if you're behind a reverse proxy (Nginx, Apache...), you can get the same rate-limiting result.

Install

$ npm i --save node-rate-limit

Example

const express = require('express')
const RateLimit = require('node-rate-limit')
const redis = require('redis')

const app = express()
const cache = redis.createClient()

const limiter = new RateLimit({
  max: 10, // ten times per duration
  duration: 10 * 1000, // 10 seconds
  cache: cache // redis instance
})
app.use(limiter)

Configuration

max: [optional] max times per duration. The default is 10.

duration: [optional] how long to keep the records of requests. The default is 1000 milliseconds.

cache: [optional] redis client instance. The default is memory cache.

About

express rate-limiting middleware

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published