VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-agent-maxsockets-method/

⇱ Node.js agent.maxSockets Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js agent.maxSockets Method

Last Updated : 1 Oct, 2020

The Node.js HTTP API is low-level so that it could support the HTTP applications. In order to access and use the HTTP server and client, we need to call them (by ‘require(‘http’)‘). HTTP message headers are represented as JSON Format.

The agent.maxSockets (Added in v0.3.6) method is an inbuilt application programming interface of the ‘Http‘ module which determines how many concurrent sockets the agent can have open per origin. Origin is the returned value of agent.getName().

In order to get a response and a proper result, we need to import ‘http’ module.

Import:

const http = require('http');

Syntax:

agent.maxSockets;

Parameters: This function does not accept any parameters as mentioned above.

Return Value <number>: By default, it is set Infinity. It determines how many concurrent sockets the agent can have open per origin.

The below example illustrates the use of agent.maxSockets method in Node.js.

Example 1: Filename: index.js

Run index.js file using the following command:

node index.js

Output:

Infinity

StatusCode:  301

Reference: https://nodejs.org/api/http.html#http_agent_maxsockets

Comment

Explore