Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/harkal/fast-throttler
https://github.com/harkal/fast-throttler
npm npm-package redis throttling webapp
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/harkal/fast-throttler
- Owner: harkal
- Created: 2016-08-24T16:28:54.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-07-07T08:30:46.000Z (over 4 years ago)
- Last Synced: 2024-10-07T21:41:02.813Z (3 months ago)
- Topics: npm, npm-package, redis, throttling, webapp
- Language: JavaScript
- Size: 542 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
![alt text](https://github.com/Besssy/fast-throttler/blob/master/images/logo.png)
[![NPM Version](https://img.shields.io/npm/v/fast-throttler.svg)](https://www.npmjs.com/package/fast-throttler)
## Description
Throttle the amount of times your function runs by adding a limit.## Installation
` npm install fast-throttler --save `
## Simple Usage
```javascript
const Throttler = require('fast-throttler');
var throttler = new Throttler({rate: 2}); //will throttle 2 requests per second
```For example, you can throttle a GET request per _product id_ in Express.js like this
```javascript
router.get('/product/:id', function(req, res){
throttler(req.params.id)
.then(function(){
//...
res.render('template', productData);
})
.catch(function(error){
//...
res.status(429); //Too many requests
});
});
```## Options
|Parameter|Type|Default Value|
|:---------:|:----:|:-------------:|
|Rate|Number|1024|
|Period|Number|1|
|Cost|Function|()=>1|
|Key|Function|(key)=>key|## Events
|Name|Description|
|---------:|:----|
|onAllowed|Executes when throttler is operating within limits|
|onThrottled|Executes when throttler rate is overreached |