Gathering detailed insights and metrics for connect-timeout
Gathering detailed insights and metrics for connect-timeout
Gathering detailed insights and metrics for connect-timeout
Gathering detailed insights and metrics for connect-timeout
npm install connect-timeout
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
316 Stars
140 Commits
48 Forks
15 Watching
1 Branches
30 Contributors
Updated on 25 Oct 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-7.5%
54,364
Compared to previous day
Last week
4.4%
328,530
Compared to previous week
Last month
10.6%
1,322,561
Compared to previous month
Last year
25.3%
14,002,550
Compared to previous year
Times out a request in the Connect/Express application framework.
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
1$ npm install connect-timeout
NOTE This module is not recommend as a "top-level" middleware (i.e.
app.use(timeout('5s'))
) unless you take precautions to halt your own
middleware processing. See as top-level middleware
for how to use as a top-level middleware.
While the library will emit a 'timeout' event when requests exceed the given timeout, node will continue processing the slow request until it terminates. Slow requests will continue to use CPU and memory, even if you are returning a HTTP response in the timeout callback. For better control over CPU/memory, you may need to find the events that are taking a long time (3rd party HTTP requests, disk I/O, database calls) and find a way to cancel them, and/or close the attached sockets.
Returns middleware that times out in time
milliseconds. time
can also
be a string accepted by the ms
module. On timeout, req
will emit "timeout"
.
The timeout
function takes an optional options
object that may contain
any of the following keys:
Controls if this module will "respond" in the form of forwarding an error.
If true
, the timeout error is passed to next()
so that you may customize
the response behavior. This error has a .timeout
property as well as
.status == 503
. This defaults to true
.
Clears the timeout on the request. The timeout is completely removed and will not fire for this request in the future.
true
if timeout fired; false
otherwise.
Because of the way middleware processing works, once this module passes the request to the next middleware (which it has to do in order for you to do work), it can no longer stop the flow, so you must take care to check if the request has timedout before you continue to act on the request.
1var bodyParser = require('body-parser') 2var cookieParser = require('cookie-parser') 3var express = require('express') 4var timeout = require('connect-timeout') 5 6// example of using this top-level; note the use of haltOnTimedout 7// after every middleware; it will stop the request flow on a timeout 8var app = express() 9app.use(timeout('5s')) 10app.use(bodyParser()) 11app.use(haltOnTimedout) 12app.use(cookieParser()) 13app.use(haltOnTimedout) 14 15// Add your routes here, etc. 16 17function haltOnTimedout (req, res, next) { 18 if (!req.timedout) next() 19} 20 21app.listen(3000)
1var express = require('express') 2var bodyParser = require('body-parser') 3var timeout = require('connect-timeout') 4 5var app = express() 6app.post('/save', timeout('5s'), bodyParser.json(), haltOnTimedout, function (req, res, next) { 7 savePost(req.body, function (err, id) { 8 if (err) return next(err) 9 if (req.timedout) return 10 res.send('saved as id ' + id) 11 }) 12}) 13 14function haltOnTimedout (req, res, next) { 15 if (!req.timedout) next() 16} 17 18function savePost (post, cb) { 19 setTimeout(function () { 20 cb(null, ((Math.random() * 40000) >>> 0)) 21 }, (Math.random() * 7000) >>> 0) 22} 23 24app.listen(3000)
1var bodyParser = require('body-parser') 2var connect = require('connect') 3var timeout = require('connect-timeout') 4 5var app = connect() 6app.use('/save', timeout('5s'), bodyParser.json(), haltOnTimedout, function (req, res, next) { 7 savePost(req.body, function (err, id) { 8 if (err) return next(err) 9 if (req.timedout) return 10 res.send('saved as id ' + id) 11 }) 12}) 13 14function haltOnTimedout (req, res, next) { 15 if (!req.timedout) next() 16} 17 18function savePost (post, cb) { 19 setTimeout(function () { 20 cb(null, ((Math.random() * 40000) >>> 0)) 21 }, (Math.random() * 7000) >>> 0) 22} 23 24app.listen(3000)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
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
branch protection not enabled on development/release branches
Details
Reason
security policy file not 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