I believe in node.js, there's a server.timeout
setting. Do you know how to set the server timeout in express.js?
Asked
Active
Viewed 1.0k times
5

iPhoneJavaDev
- 821
- 5
- 33
- 78
-
I found this issue from the official Express GitHub page https://github.com/expressjs/express/issues/3330 – Felix Fong Oct 23 '18 at 08:22
-
Man can I have you kind comment on my answer ? – bereket gebredingle Nov 11 '18 at 03:59
1 Answers
7
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

bereket gebredingle
- 12,064
- 3
- 36
- 47