https://github.com/four43/node-express-enqueue
A rate-limiting middleware that ensures only the desired number of requests are being worked on concurrently.
https://github.com/four43/node-express-enqueue
expressjs nodejs queue request
Last synced: 10 months ago
JSON representation
A rate-limiting middleware that ensures only the desired number of requests are being worked on concurrently.
- Host: GitHub
- URL: https://github.com/four43/node-express-enqueue
- Owner: four43
- License: mit
- Created: 2016-05-19T01:59:09.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2018-02-07T04:23:40.000Z (over 8 years ago)
- Last Synced: 2025-08-09T05:54:37.546Z (10 months ago)
- Topics: expressjs, nodejs, queue, request
- Language: JavaScript
- Size: 22.5 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-express-enqueue
A rate-limiting middleware that ensures only the desired number of requests are being worked on concurrently.
[](https://travis-ci.org/four43/node-express-enqueue)
[](https://coveralls.io/github/four43/node-express-enqueue?branch=master)
## Example
`express-enqueue` is instantiated before use:
```javascript
const Enqueue = require('express-enqueue'),
app = require('express')();
const queue = new Enqueue({
concurrentWorkers: 4,
maxSize: 200,
timeout: 30000
});
app.use(queue.getMiddleware());
app.get('/hello', (req, res) => res.json({hello:'world'}));
app.use(queue.getErrorMiddleware());
app.listen(9000);
```
## Options
| Option | Type (default) | Description |
|---------------------|----------------------------|--------------------------------------------------------------------------------------------------------------------|
| `concurrentWorkers` | Integer (# of cores) | The number of concurrent workers, how many requests should be worked on at once. |
| `queueMaxSize` | Integer (1000) | The maximum number of open requests. |
| `timeout` | Integer,time in ms. (none) | If a request has been sitting the queue for more than this time, it will be skipped and an error will be returned. |
## Methods
### getMiddleware()
Gets the Express middleware. This queue can be used app-wide or to limit a specific controller.
### getErrorMiddleware(`json`)
Gets the error handling middleware that will parse `express-enqueue` specific errors and send appropriate error codes and messages. It will output them in JSON by default, but when the first argument is set to false it will just output the message.
### getStats()
Returns stats about the queue, `{{total: number, inProgress: number, waiting: number}}`