我正在编写一个需要与服务器通信的Node.js应用程序。它使用以下代码建立http连接:
var client = http.createClient(u.port, u.hostname, u.secure);
client.on("error", function(exception) {
logger.error("error from client");
});
var request = client.request(method, u.path, headers);
我在 node.js 文档中没有找到设置连接超时的选项,它似乎默认为20秒。我的问题是,我们的数据中心位于美国,而在中国的用户使用似乎比较慢或不稳定的网络,有时会在连接时出现超时错误。我想将超时时间增加到1分钟,看看是否可以解决这个问题。
在 node.js 中有没有办法做到这一点?