Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Node Rate Limiter Flexible | 2,389 | 68 | 81 | 2 months ago | 146 | September 25, 2022 | 9 | isc | JavaScript | |
Count and limit requests by key with atomic increments in single process or distributed environment. | ||||||||||
Laravel Love | 1,014 | 11 | 2 | a month ago | 51 | February 23, 2022 | 7 | mit | PHP | |
Add Social Reactions to Laravel Eloquent Models. It lets people express how they feel about the content. Fully customizable Weighted Reaction System & Reaction Type System with Like, Dislike and any other custom emotion types. Do you react? | ||||||||||
Express Limiter | 401 | 117 | 25 | 4 years ago | 9 | September 18, 2017 | 24 | mit | JavaScript | |
Rate limiting middleware for Express | ||||||||||
Limitrr | 204 | 2 years ago | 57 | April 20, 2020 | mit | JavaScript | ||||
Light NodeJS rate limiting and response delaying using Redis - including Express middleware. | ||||||||||
Rate Limit Redis | 135 | 80 | 22 | 4 months ago | 16 | March 10, 2022 | 6 | mit | TypeScript | |
A rate limiting store for express-rate-limit with Redis | ||||||||||
Express Rate | 86 | 8 years ago | 11 | JavaScript | ||||||
Rate monitoring and limiting for express.js apps | ||||||||||
Express Es8 Rest Boilerplate | 81 | 3 years ago | 18 | mit | JavaScript | |||||
Node.js boilerplate for building RESTful APIs using Express, MongoDB, Passport, Mocha using ES2017(ES8) syntax | ||||||||||
Rxxpress | 74 | 3 months ago | 8 | June 03, 2020 | 15 | mit | TypeScript | |||
An Experimental Mashup of RxJS and Express | ||||||||||
Express Prometheus Middleware | 73 | 2 | 11 | a year ago | 27 | April 24, 2021 | 17 | mit | JavaScript | |
A ready to use RED/USE prometheus metrics exporter for express applications | ||||||||||
Awesome Usps | 33 | 11 years ago | 1 | mit | Ruby | |||||
Submitted Description: A ruby wrapper around the various USPS APIs for generating rates, tracking information, label generation, and address checking. |
Rate limiting middleware for Express applications built on redis
npm install express-limiter --save
var express = require('express')
var app = express()
var client = require('redis').createClient()
var limiter = require('express-limiter')(app, client)
/**
* you may also pass it an Express 4.0 `Router`
*
* router = express.Router()
* limiter = require('express-limiter')(router, client)
*/
limiter({
path: '/api/action',
method: 'get',
lookup: ['connection.remoteAddress'],
// 150 requests per hour
total: 150,
expire: 1000 * 60 * 60
})
app.get('/api/action', function (req, res) {
res.send(200, 'ok')
})
limiter(options)
path
: String
optional route path to the requestmethod
: String
optional http method. accepts get
, post
, put
, delete
, and of course Express' all
lookup
: Function|String|Array.<String>
value lookup on the request object. Can be a single value, array or function. See examples for common usagestotal
: Number
allowed number of requests before getting rate limitedexpire
: Number
amount of time in ms
before the rate-limited is resetwhitelist
: function(req)
optional param allowing the ability to whitelist. return boolean
, true
to whitelist, false
to passthru to limiter.skipHeaders
: Boolean
whether to skip sending HTTP headers for rate limits ()ignoreErrors
: Boolean
whether errors generated from redis should allow the middleware to call next(). Defaults to false.onRateLimited
: Function
called when a request exceeds the configured rate limit.// limit by IP address
limiter({
...
lookup: 'connection.remoteAddress'
...
})
// or if you are behind a trusted proxy (like nginx)
limiter({
lookup: 'headers.x-forwarded-for'
})
// by user (assuming a user is logged in with a valid id)
limiter({
lookup: 'user.id'
})
// limit your entire app
limiter({
path: '*',
method: 'all',
lookup: 'connection.remoteAddress'
})
// limit users on same IP
limiter({
path: '*',
method: 'all',
lookup: ['user.id', 'connection.remoteAddress']
})
// whitelist user admins
limiter({
path: '/delete/thing',
method: 'post',
lookup: 'user.id',
whitelist: function (req) {
return !!req.user.is_admin
}
})
// skip sending HTTP limit headers
limiter({
path: '/delete/thing',
method: 'post',
lookup: 'user.id',
whitelist: function (req) {
return !!req.user.is_admin
},
skipHeaders: true
})
// call a custom limit handler
limiter({
path: '*',
method: 'all',
lookup: 'connection.remoteAddress',
onRateLimited: function (req, res, next) {
next({ message: 'Rate limit exceeded', status: 429 })
}
})
// with a function for dynamic-ness
limiter({
lookup: function(req, res, opts, next) {
if (validApiKey(req.query.api_key)) {
opts.lookup = 'query.api_key'
opts.total = 100
} else {
opts.lookup = 'connection.remoteAddress'
opts.total = 10
}
return next()
}
})
app.post('/user/update', limiter({ lookup: 'user.id' }), function (req, res) {
User.find(req.user.id).update(function (err) {
if (err) next(err)
else res.send('ok')
})
})
Happy Rate Limiting!