Registry / http-networking / express-throttle

express-throttle

JSON →
library2.0.0jsnpmunverified

Request throttling middleware for Express using a token bucket algorithm with sliding window refill. Version 2.0.0 is current stable. Enables per-route rate limiting with configurable burst capacity, rate, and key function (defaults to IP address). Supports half-requests and custom cost per request. Limitations: in-memory storage by default (not shared across processes), and race conditions when using custom external backends under high load. Recommended for single-process apps.

npm install express-throttle
INSTALL
IMPORT
SIG · EXPRESS-THROTTLE
E
express-throttle
http-networkingjavascriptv2.0.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

throttle
✓ const throttle = require('express-throttle');
✗ import throttle from 'express-throttle';
Package uses CommonJS; no default ESM export. For TypeScript, use `import throttle = require('express-throttle');` or `const throttle = require('express-throttle');`.

Basic Express app with three rate-limited routes using express-throttle middleware.

const express = require('express'); const throttle = require('express-throttle'); const app = express(); // Allow 5 requests per second with a burst of 10 app.get('/api', throttle({ burst: 10, rate: '5/s' }), (req, res) => { res.json({ status: 'ok' }); }); // Allow 3 requests per minute (sliding window) app.post('/search', throttle({ rate: '3/m' }), (req, res) => { res.json({ result: 'search done' }); }); // Custom key function (by session username) app.use('/user', throttle({ burst: 5, rate: '1/s', key: (req) => req.session?.username ?? req.ip }), (req, res) => { res.json({ user: req.session.username }); }); app.listen(3000);
Debug
Known issues
gotchaIn-memory storage is not shared across multiple processes. Throttling is per-process when behind a load balancer.
fix
Use a shared external storage backend (e.g., Redis), but be aware of race conditions under high load. Alternatively, ensure sticky sessions.
affects: >=1.0.0
deprecatedThe `period` option (fixed time window) is deprecated in favor of `rate` (sliding window).
fix
Use `rate` for sliding window throttling instead of `period`.
affects: >=2.0.0
gotchaThe default key function uses `req.ip`, which may return the load balancer's IP if not configured correctly.
fix
Configure Express trust proxy settings and provide a custom `key` function that uses `req.connection.remoteAddress` or `req.headers['x-forwarded-for']`.
affects: >=1.0.0
gotchaHalf requests (0.5 cost) are allowed but may lead to unexpected behavior if not integral tokens.
fix
Use integer `cost` values to avoid fractional token counting.
affects: >=1.0.0
gotchaExternal storage backends have race conditions; high load may cause erroneous throttling or allowing requests.
fix
Use in-memory storage for single-process apps, or wait for a future version with atomic operations.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: throttle is not a function
Importing as default ESM import (`import throttle from 'express-throttle'`) while package exports CommonJS.
fix
Use `const throttle = require('express-throttle');` or `import * as throttle from 'express-throttle';`
RangeError: Invalid rate string: '10/minutes'
Rate string format is incorrect. Valid format: number/unit (e.g., '5/s', '10/m', '2/h'). Unit must be one of 's', 'm', 'h'.
fix
Use correct rate string like '10/m' for 10 per minute.
Error: Cannot find module 'express-throttle'
Package not installed.
fix
Run `npm install express-throttle` in your project directory.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
expressrequiredPeer dependency; throttling middleware for Express framework.
Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
express-throttle — npm install express-throttle · libregistry