{"id":18362,"library":"express-timeout-handler","title":"express-timeout-handler","description":"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.","status":"maintenance","version":"2.2.2","language":"javascript","source_language":"en","source_url":"https://github.com/debitoor/express-timeout-handler","tags":["javascript"],"install":[{"cmd":"npm install express-timeout-handler","lang":"bash","label":"npm"},{"cmd":"yarn add express-timeout-handler","lang":"bash","label":"yarn"},{"cmd":"pnpm add express-timeout-handler","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency: designed as Express middleware, requires Express app instance","package":"express","optional":false}],"imports":[{"note":"Package is CommonJS-only; no ES module version. Use require.","wrong":"import timeout from 'express-timeout-handler';","symbol":"timeoutHandler","correct":"const timeout = require('express-timeout-handler');"},{"note":"Must call timeout.handler(), not timeout directly.","wrong":"app.use(timeout(options));","symbol":"handler","correct":"app.use(timeout.handler(options));"},{"note":"timeout.set() returns route-specific middleware; do not call on app level.","wrong":"app.use(timeout.set(4000));","symbol":"set","correct":"timeout.set(4000);"}],"quickstart":{"code":"const express = require('express');\nconst timeout = require('express-timeout-handler');\nconst app = express();\n\nconst options = {\n  timeout: 5000,\n  onTimeout: function(req, res) {\n    res.status(503).send('Service unavailable. Please retry.');\n  },\n  onDelayedResponse: function(req, method, args, requestTime) {\n    console.log('Delayed response after timeout:', method);\n  },\n  disable: ['write', 'send', 'json', 'end']\n};\n\napp.use(timeout.handler(options));\n\napp.get('/greet', function (req, res) {\n  setTimeout(() => res.send('Hello'), 6000); // Will timeout\n});\n\napp.get('/leave', timeout.set(2000), function (req, res) {\n  setTimeout(() => res.send('Goodbye'), 1000);\n});\n\napp.listen(3000, () => console.log('running'));\n","lang":"javascript","description":"Demonstrates default global timeout and per-route override with timeout.set(), including onTimeout callback."},"warnings":[{"fix":"Always call res.status().send() or similar in onTimeout.","message":"onTimeout callback MUST terminate the request (call res.end/send/json) otherwise the request hangs indefinitely.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Implement manual timeout handling inside stream if needed.","message":"Streaming responses are not interrupted by timeout handler; if a response stream started before timeout, onTimeout will not fire.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set disable array carefully; consider omitting it to use defaults.","message":"Disabling methods like 'write' and 'end' can break middleware that attempts to write response after timeout.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Update options to use new property names.","message":"In v2.0.0, the signature changed: options object now expects 'onTimeout' instead of 'timeoutHandler' and 'disable' replaced 'protectedMethods'.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Consider alternatives like 'express-timeout' or custom middleware.","message":"The package is no longer actively maintained; last update 2019.","severity":"deprecated","affected_versions":">=2.2.2"}],"env_vars":null,"search_vec":"'2.0.0':32 '2.2.2':25 '2017':33 '4':67 '6':64 'activ':43 'cadenc':29 'call':16 'connect':36 'connect-timeout':35 'current':21 'custom':18 'disabl':12,49 'doubl':46 'double-send':45 'enforc':8 'express':2,5,66 'express-timeout-handl':1 'handler':4,20 'javascript':69 'last':30 'low':27 'major':31 'method':14,51 'middlewar':6,41 'node':63 'ontimeout':19 'per':57 'per-rout':56 'prevent':44 'releas':28 'requir':62 'respons':9,13,50 'rout':58 'send':47 'stabl':22 'support':55 'timeout':3,10,37,40,53,59 'timeout.set':61 'unlik':34 'version':23 'via':60 'x':68","created_at":"2026-04-25T07:37:49.908942+00:00","updated_at":"2026-04-25T07:37:49.908942+00:00","problems":[{"fix":"Use require('express-timeout-handler').","cause":"Using import ES module syntax on a CommonJS package; or incorrect import path.","error":"TypeError: timeout.handler is not a function"},{"fix":"Ensure onTimeout calls res.end() or similar; check disable array if too restrictive.","cause":"onTimeout did not send a response, or another middleware called res.send after timeout.","error":"TimeoutError: The response object was ended after the request timed out"},{"fix":"Call app.use(timeout.handler(options)) after express() and before routes.","cause":"timeout.handler(options) was attached before Express app initialization or on non-request object.","error":"Cannot set property 'globalTimeout' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/debitoor/express-timeout-handler","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/express-timeout-handler","openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking","web-framework"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-24","install_tag":null}}