跳至主要内容

[Node] NodeJS Tips 小技巧筆記

常見問題

Error: ECONNRESET

嘗試設定 maxSocket 的數量,預設是無上限:

var http = require('http'); // Do the same with the 'https' module if you do https requests
var httpAgent = new http.Agent();
httpAgent.maxSockets = 15;

let options = {
pool: httpAgent,
};

如果是透過 requestJS 可以嘗試設定 pool: {maxSockets: 15}timeout

let options = {
url: 'http://foo.bar',
timeout: 30000,
pool: { maxSockets: 15 },
};

request(options, (err, res, body) => {});

How to set max concurrent connections and a queue? @ requestJS Github Issues http @ NodeJS Doc