简体   繁体   中英

Set HTTP timeout in Node.js

I'm working on an app that uses Node.js as the backend. Currently, I have a web server setup like this:

var express = require('express');
var http = require('http');

var app = module.exports.app = express();
http.createServer(app).listen(appConfig.port, function () {
    var logger = app.get('logger');
    logger.info('**** STARTING SERVER ****');
});

My app is working just fine. Except, I have now added a request that is takes ~5 minutes. From my understanding, Node defaults to a 2 minute timeout window. I can read the documentation here . However, I don't understand how to set the timeout to a greater value.

Can someone show me how to increase the timeout to 10 minutes?

this should set it. you need a reference to the server object then set the timeout

var express = require('express');
var http = require('http');

var app = module.exports.app = express();
var server = http.createServer(app);
server.setTimeout(10*60*1000); // 10 * 60 seconds * 1000 msecs
server.listen(appConfig.port, function () {
    var logger = app.get('logger');
    logger.info('**** STARTING SERVER ****');
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM