Registry / http-networking / express-timeout-handler

express-timeout-handler

JSON →
library2.2.2jsnpmunverified

Express middleware that enforces response timeouts by disabling response methods and calling a custom onTimeout handler. Current stable version is 2.2.2, with low release cadence (last major 2.0.0 ~2017). Unlike connect-timeout or other timeout middlewares, it actively prevents double-send by disabling response methods after timeout and supports per-route timeouts via timeout.set(). Requires Node >=6 and Express 4.x.

npm install express-timeout-handler
INSTALL
IMPORT
SIG · EXPRESS-TIMEOUT-HA
E
express-timeout-handler
http-networkingjavascriptv2.2.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

timeoutHandler
const timeout = require('express-timeout-handler');
import timeout from 'express-timeout-handler';
Package is CommonJS-only; no ES module version. Use require.
handler
app.use(timeout.handler(options));
app.use(timeout(options));
Must call timeout.handler(), not timeout directly.
set
timeout.set(4000);
app.use(timeout.set(4000));
timeout.set() returns route-specific middleware; do not call on app level.

Demonstrates default global timeout and per-route override with timeout.set(), including onTimeout callback.

const express = require('express'); const timeout = require('express-timeout-handler'); const app = express(); const options = { timeout: 5000, onTimeout: function(req, res) { res.status(503).send('Service unavailable. Please retry.'); }, onDelayedResponse: function(req, method, args, requestTime) { console.log('Delayed response after timeout:', method); }, disable: ['write', 'send', 'json', 'end'] }; app.use(timeout.handler(options)); app.get('/greet', function (req, res) { setTimeout(() => res.send('Hello'), 6000); // Will timeout }); app.get('/leave', timeout.set(2000), function (req, res) { setTimeout(() => res.send('Goodbye'), 1000); }); app.listen(3000, () => console.log('running'));
Debug
Known issues
gotchaonTimeout callback MUST terminate the request (call res.end/send/json) otherwise the request hangs indefinitely.
fix
Always call res.status().send() or similar in onTimeout.
affects: >=2.0.0
gotchaStreaming responses are not interrupted by timeout handler; if a response stream started before timeout, onTimeout will not fire.
fix
Implement manual timeout handling inside stream if needed.
affects: >=1.0.0
gotchaDisabling methods like 'write' and 'end' can break middleware that attempts to write response after timeout.
fix
Set disable array carefully; consider omitting it to use defaults.
affects: >=2.0.0
breakingIn v2.0.0, the signature changed: options object now expects 'onTimeout' instead of 'timeoutHandler' and 'disable' replaced 'protectedMethods'.
fix
Update options to use new property names.
affects: >=2.0.0
deprecatedThe package is no longer actively maintained; last update 2019.
fix
Consider alternatives like 'express-timeout' or custom middleware.
affects: >=2.2.2
Errors
Common errors & fixes
TypeError: timeout.handler is not a function
Using import ES module syntax on a CommonJS package; or incorrect import path.
fix
Use require('express-timeout-handler').
TimeoutError: The response object was ended after the request timed out
onTimeout did not send a response, or another middleware called res.send after timeout.
fix
Ensure onTimeout calls res.end() or similar; check disable array if too restrictive.
Cannot set property 'globalTimeout' of undefined
timeout.handler(options) was attached before Express app initialization or on non-request object.
fix
Call app.use(timeout.handler(options)) after express() and before routes.
Upgrade
Version history
2.2.2latest on npm
Audit
Dependencies
expressrequiredpeer dependency: designed as Express middleware, requires Express app instance
Agent activity
8 hits · last 30 days
node
6
Amazon
1
OpenAI (training)
1
Resources
express-timeout-handler — npm install express-timeout-handler · libregistry