TIMEX
TIMEX

Reputation: 272144

How come I can't load this http module in Node.js?

var http = require('http').globalAgent.maxSockets = 99;

    TypeError: Cannot set property 'maxSockets' of undefined

I want to se the number of maxSockets to 99, no matter what. But when I load that line, it says that globalAgent is undefined??

Also - if I put this line of code in my app.js, will it hold throughout my entire project? For example, if I require another module, which that module requires "request" module...and that request module requires http...will it keep maxSockets at 99 because I have this line of code early in my app.js before everything else?

Basically, I want 99 maxSockets for everything in my app.js and all its submodules and all those submodules.

Upvotes: 1

Views: 1495

Answers (1)

mike
mike

Reputation: 7177

What version of Node.js? Looks like http.globalAgent was added in v0.5.3.

The globalAgent.maxSockets should be global throughout other modules requiring http.

Also, you probably want to split up setting maxSockets, unless you really want to assign http the value 99.

var http = require('http');
http.globalAgent.maxSockets = 99;

If you don't split up the assignment, you'll have a problem if you try to use the http var later, like

var http = require('http').globalAgent.maxSockets = 99;
http.createServer();

Upvotes: 2

Related Questions