简体   繁体   English

在Node.js中设置HTTP超时

[英]Set HTTP timeout in Node.js

I'm working on an app that uses Node.js as the backend. 我正在开发一个使用Node.js作为后端的应用程序。 Currently, I have a web server setup like this: 当前,我有这样的Web服务器设置:

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. 除此之外,我现在添加了一个大约需要5分钟的请求。 From my understanding, Node defaults to a 2 minute timeout window. 据我了解,Node默认为2分钟超时窗口。 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? 有人可以告诉我如何将超时时间增加到10分钟吗?

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 ****');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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