Gathering detailed insights and metrics for express-timeout-handler
Gathering detailed insights and metrics for express-timeout-handler
Gathering detailed insights and metrics for express-timeout-handler
Gathering detailed insights and metrics for express-timeout-handler
npm install express-timeout-handler
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
17 Stars
54 Commits
4 Forks
25 Watching
7 Branches
36 Contributors
Updated on 23 Nov 2021
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-11.3%
6,599
Compared to previous day
Last week
-8.3%
37,865
Compared to previous week
Last month
16.2%
181,738
Compared to previous month
Last year
-32.3%
1,254,770
Compared to previous year
9
Express timeout middleware that ensures a response is returned to the client on a timeout event.
Add 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.
Note 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.
npm install --save express-timeout-handler
1var timeout = require('express-timeout-handler'); 2var express = require('express'); 3var app = express(); 4 5var options = { 6 7 // Optional. This will be the default timeout for all endpoints. 8 // If omitted there is no default timeout on endpoints 9 timeout: 3000, 10 11 // Optional. This function will be called on a timeout and it MUST 12 // terminate the request. 13 // If omitted the module will end the request with a default 503 error. 14 onTimeout: function(req, res) { 15 res.status(503).send('Service unavailable. Please retry.'); 16 }, 17 18 // Optional. Define a function to be called if an attempt to send a response 19 // happens after the timeout where: 20 // - method: is the method that was called on the response object 21 // - args: are the arguments passed to the method 22 // - requestTime: is the duration of the request 23 // timeout happened 24 onDelayedResponse: function(req, method, args, requestTime) { 25 console.log(`Attempted to call ${method} after timeout`); 26 }, 27 28 // Optional. Provide a list of which methods should be disabled on the 29 // response object when a timeout happens and an error has been sent. If 30 // omitted, a default list of all methods that tries to send a response 31 // will be disable on the response object 32 disable: ['write', 'setHeaders', 'send', 'json', 'end']; 33}; 34 35app.use(timeout.handler(options)); 36 37app.get('/greet', //The default timeout is in effect here 38 function (req, res) { 39 res.send('Hello world!'); 40 } 41); 42 43app.get('/leave', 44 // This is a specific endpoint timeout which overrides the default timeout 45 timeout.set(4000), 46 function (req, res) { 47 res.send('Goodbye!'); 48 } 49); 50 51app.listen(3000, function () { 52 console.log('Server listening on port 3000'); 53});
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
Found 3/16 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
43 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More