I believe in node.js, there's a server.timeout setting. Do you know how to set the server timeout in express.js?
-
I found this issue from the official Express GitHub page github.com/expressjs/express/issues/3330Felix Fong– Felix Fong2018-10-23 08:22:53 +00:00Commented Oct 23, 2018 at 8:22
-
Man can I have you kind comment on my answer ?bereket gebredingle– bereket gebredingle2018-11-11 03:59:49 +00:00Commented Nov 11, 2018 at 3:59
Add a comment
|
1 Answer
var timeout = express.timeout // express v3 and below
var timeout = require('connect-timeout'); //express v4
app.use(timeout(120000));
app.use(haltOnTimedout);
function haltOnTimedout(req, res, next){
if (!req.timedout) next();
}
Or without other modules
app.use(function(req, res, next){
res.setTimeout(120000, function(){
console.log('Request has timed out.');
res.send(408);
});
next();
});
inspired by Express.js Response Timeout