Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you set maxSockets in Node.js when using Express?

Is there a way to modify the Node.js maxSockets setting when using the Express framework?

like image 880
James Simpson Avatar asked Apr 25 '12 00:04

James Simpson


2 Answers

Somewhere after you do var http = require('http'), just add http.globalAgent.maxSockets = x (where 'x' is the number of sockets you want).

Please note that if you are making requests over https, you will need to set maxSockets for https as well.

var https = require('https');
https.globalAgent.maxSockets = your_val_here;
like image 100
danmactough Avatar answered Oct 21 '22 20:10

danmactough


From version v0.12.0 maxSockets set to Infinity

maxSockets are no longer limited to 5. The default is now set to Infinity with the developer and the operating system given control over how many simultaneous connections an application can keep open to a given host.

Node v0.12.0 (Stable) release notes

like image 45
MosheZada Avatar answered Oct 21 '22 18:10

MosheZada