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

16,596

Solution 1

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;

Solution 2

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

Share:
16,596
James Simpson
Author by

James Simpson

CEO & Founder of GoldFire Studios. Business is my game, and games are my business.

Updated on June 14, 2022

Comments

  • James Simpson
    James Simpson almost 2 years

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

  • James Simpson
    James Simpson almost 12 years
    I never do require('http') though, just require('express').
  • danmactough
    danmactough almost 12 years
    Okay, then require it! :) Like it says, it's a global setting (for that process), so however you set it, express will use that setting.