5

I believe in node.js, there's a server.timeout setting. Do you know how to set the server timeout in express.js?

iPhoneJavaDev
  • 821
  • 5
  • 33
  • 78

1 Answers1

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