1.0.0 • Published 6 years ago

express-enqueue v1.0.0

Weekly downloads
113
License
MIT
Repository
github
Last release
6 years ago

node-express-enqueue

A rate-limiting middleware that ensures only the desired number of requests are being worked on concurrently.

Build Status Coverage Status

Example

express-enqueue is instantiated before use:

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

OptionType (default)Description
concurrentWorkersInteger (# of cores)The number of concurrent workers, how many requests should be worked on at once.
queueMaxSizeInteger (1000)The maximum number of open requests.
timeoutInteger,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}}