{"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,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","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,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}