{"id":18291284,"url":"https://github.com/debitoor/express-timeout-handler","last_synced_at":"2025-04-05T10:31:00.788Z","repository":{"id":48507609,"uuid":"63315523","full_name":"debitoor/express-timeout-handler","owner":"debitoor","description":null,"archived":false,"fork":false,"pushed_at":"2021-07-22T09:08:10.000Z","size":200,"stargazers_count":17,"open_issues_count":2,"forks_count":4,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-03-21T03:03:02.302Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/debitoor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-14T08:02:52.000Z","updated_at":"2021-11-23T16:16:28.000Z","dependencies_parsed_at":"2022-09-10T01:51:35.167Z","dependency_job_id":null,"html_url":"https://github.com/debitoor/express-timeout-handler","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/debitoor%2Fexpress-timeout-handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/debitoor%2Fexpress-timeout-handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/debitoor%2Fexpress-timeout-handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/debitoor%2Fexpress-timeout-handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/debitoor","download_url":"https://codeload.github.com/debitoor/express-timeout-handler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247324537,"owners_count":20920669,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T14:13:49.771Z","updated_at":"2025-04-05T10:31:00.465Z","avatar_url":"https://github.com/debitoor.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# express-timeout-handler\n\n[![npm version](https://badge.fury.io/js/express-timeout-handler.svg)](https://badge.fury.io/js/express-timeout-handler) [![Build Status](https://travis-ci.org/debitoor/express-timeout-handler.svg?branch=master)](https://travis-ci.org/debitoor/express-timeout-handler) [![Dependency Status](https://david-dm.org/debitoor/express-timeout-handler.svg)](https://david-dm.org/debitoor/express-timeout-handler) [![devDependency Status](https://david-dm.org/debitoor/express-timeout-handler/dev-status.svg)](https://david-dm.org/debitoor/express-timeout-handler#info=devDependencies) [![Coverage Status](https://coveralls.io/repos/github/debitoor/express-timeout-handler/badge.svg?branch=master)](https://coveralls.io/github/debitoor/express-timeout-handler?branch=master)\n\nExpress timeout middleware that ensures a response is returned to the client on a timeout event.\n\nAdd a global timeout to all your routes in express and add individual timeouts to specific routes. If a timeout happens the ``onTimeout`` function will be called. The ``onTimeout`` function MUST terminate the request with a response. When a timeout happens, this module will set a ``globalTimeout`` property on the response object to true and disable all methods on the response object which might try and send something after the timeout happened.\n\nNote on streams: whenever a stream has started streaming to the response object, the ``onTimeout`` function will not be triggered. Or in other words: if a timeout happens after we start streaming, the stream will not be interrupted.\n\n\tnpm install --save express-timeout-handler\n\n## Usage\n\n```javascript\nvar timeout = require('express-timeout-handler');\nvar express = require('express');\nvar app = express();\n\nvar options = {\n\n  // Optional. This will be the default timeout for all endpoints.\n  // If omitted there is no default timeout on endpoints\n  timeout: 3000,\n\n  // Optional. This function will be called on a timeout and it MUST\n  // terminate the request.\n  // If omitted the module will end the request with a default 503 error.\n  onTimeout: function(req, res) {\n    res.status(503).send('Service unavailable. Please retry.');\n  },\n\n  // Optional. Define a function to be called if an attempt to send a response\n  // happens after the timeout where:\n  // - method: is the method that was called on the response object\n  // - args: are the arguments passed to the method\n  // - requestTime: is the duration of the request\n  // timeout happened\n  onDelayedResponse: function(req, method, args, requestTime) {\n    console.log(`Attempted to call ${method} after timeout`);\n  },\n\n  // Optional. Provide a list of which methods should be disabled on the\n  // response object when a timeout happens and an error has been sent. If\n  // omitted, a default list of all methods that tries to send a response\n  // will be disable on the response object\n  disable: ['write', 'setHeaders', 'send', 'json', 'end'];\n};\n\napp.use(timeout.handler(options));\n\napp.get('/greet', //The default timeout is in effect here\n  function (req, res) {\n    res.send('Hello world!');\n  }\n);\n\napp.get('/leave',\n  // This is a specific endpoint timeout which overrides the default timeout\n  timeout.set(4000),\n  function (req, res) {\n    res.send('Goodbye!');\n  }\n);\n\napp.listen(3000, function () {\n  console.log('Server listening on port 3000');\n});\n```\n\n## License\n\n[MIT](http://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdebitoor%2Fexpress-timeout-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdebitoor%2Fexpress-timeout-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdebitoor%2Fexpress-timeout-handler/lists"}