express-queue

raw JSON →
0.0.13 verified Sat Apr 25 auth: no javascript

Express middleware that limits the number of simultaneously processed requests by queuing excess requests. Version 0.0.13, stable but low activity. Supports configurable active limit and queued limit with optional custom rejection handler. Uses MiniQueue internally. Differentiates from simple rate-limiters by queuing rather than dropping requests immediately.

error Middleware is not a function
cause Incorrect import (e.g., destructuring '{ queue }' from require)
fix
Use const queue = require('express-queue'); then use queue({...}) as middleware.
error Cannot find module 'express-queue'
cause Package not installed or misspelled
fix
Run 'npm install express-queue' and check package.json for correct spelling.
error queue is not a function
cause Using default import incorrectly in ESM or CommonJS
fix
In Node.js CJS: const queue = require('express-queue'); in ESM: import queue from 'express-queue';
gotcha Setting queuedLimit to 0 causes all requests to be rejected immediately
fix Set queuedLimit to -1 for unlimited queue, or a positive integer for limited queue.
gotcha Middleware must be used before routes that need queueing; otherwise requests bypass the queue
fix Ensure app.use(queue(...)) is called before any route definitions.
gotcha activeLimit must be > 0; setting to 0 will cause all requests to be queued indefinitely
fix Set activeLimit to at least 1 to allow processing.
npm install express-queue
yarn add express-queue
pnpm add express-queue

Sets up Express with queue middleware limiting concurrent requests to 2, queueing excess requests without rejection.

const express = require('express');
const queue = require('express-queue');
const app = express();

app.use(queue({ activeLimit: 2, queuedLimit: -1 }));

app.get('/', (req, res) => {
  res.send('Hello World!');
});

app.listen(3000, () => {
  console.log('Server running on port 3000');
});