Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fraybabak/throttler
a simple throttle middleware for express apps.this package works with redis
https://github.com/fraybabak/throttler
express nodejs redis routing throttling
Last synced: about 4 hours ago
JSON representation
a simple throttle middleware for express apps.this package works with redis
- Host: GitHub
- URL: https://github.com/fraybabak/throttler
- Owner: fraybabak
- License: mit
- Created: 2021-08-05T09:01:21.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-08-20T13:14:14.000Z (over 3 years ago)
- Last Synced: 2025-01-16T13:40:49.068Z (1 day ago)
- Topics: express, nodejs, redis, routing, throttling
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# throttler
a simple throttle middleware for express apps.this package works with redisyou can install it :
```
npm i @fraybabak/throttler```
simple usage:
```
const express = require('express')
const app = express()
const port = 3010// require the Throttler
const Throttler = require("@fraybabak/throttler")// create new instance with options
// there are only 3 options :
// 1. redis_address ==> redis address
// 2. limit ==> limitation per route
// 3. cooldown ==> cooldown time per secondconst throttle = new Throttler({redis_address: "127.0.0.1:6379", limit:5, cooldown: 10})
// use it like this before defining your routes
app.use((req, res, next)=>throttle.guard(req,res,next))app.get('/', (req, res) => res.send('Hello World!'))
app.get('/test', (req, res) => res.send('Hello World! again'))// will register your routes
throttle.setup(app)app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))
```