Node.js http.server.timeout Property

10 May, 2022
The http.server.timeout is an inbuilt application programming interface of class Server within http module which is used to get the default Timeout value in milliseconds. In Node.js, default server timeout is 0 milliseconds for the latest version and 2min i.e. (120000 milliseconds) for the older version.
Syntax:
server.timeout
Parameters: It does not accept any argument as a parameter.
Return Value: This property returns the default timeout value in milliseconds.
Example 1: Filename: index.js
Javascript
// Node.js program to demonstrate the // server.timeout APi   // Importing http modulevar http = require('http');   // Setting up PORTconst PORT = process.env.PORT || 3000;   // Creating http Servervar httpServer = http.createServer(  function(request, response){   // Getting the reference of the  // underlying socket object  // by using socket API  const value = response.socket;     // Display result  // by using end() api  response.end( "socket buffersize : "      + value.bufferSize, 'utf8', () => {      console.log("Displaying the result...");       // Closing server by      // using close() api      httpServer.close(()=>{          console.log("Server is closed")      })  });});   // Listening to http Server// by using listen() apihttpServer.listen(PORT, () => {    console.log("Server is running at port 3000...");}); // Getting default timeout value// by using timeout apiconst v = httpServer.timeout // Display the Timeout valueconsole.log('Default time out value :- ' + v)
Run index.js file using below command:
node index.js
Console output:
Default time out value :- 0
Server is running at port 3000...
Displaying the result...
Displaying the result...
Server is closed
Server is closed
Browser Output: Paste the localhost address http://localhost:3000/ in the search bar of the browser.
socket buffersize : 0
Example 2: Filename: index.js
Javascript
// Node.js program to demonstrate the // server.timeout APi   // Importing http modulevar http = require('http'); // Request and response handlerconst http2Handlers = (request, response) => {     // Getting the reference of the  // underlying socket object  // by using socket API  const value = response.socket;     // Display result  // by using end() api  response.end( "socket local address : "      + value.localAddress, 'utf8', () => {      console.log("Displaying the result...");       // Closing server      // by using close() api      httpServer.close(()=>{          console.log("Server is closed")      })  });  };   // Listening to http Server// by using listen() apivar httpServer = http.createServer(    http2Handlers).listen(3000, () => {    console.log("Server is running at port 3000...");}); // Getting default timeout value// by using timeout apiconst v = httpServer.timeout // Display the Default timeconsole.log('Default time out value :- ' + v)
Run index.js file using below command:
node index.js
Console Output:
Default time out value :- 0
Server is running at port 3000...
Displaying the result...
Displaying the result...
Server is closed
Server is closed
Browser Output: Paste the localhost address http://localhost:3000/ in the search bar of the browser.
socket local address : ::1
Reference: https://nodejs.org/api/http.html#http_server_timeout
varshagumber28
Node.js-Methods
Node.js
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Difference between Node.js and React.js
JWT Authentication with Node.js
How to connect Node.js with React.js ?
Node.js fs.existsSync() Method
Express.js express.urlencoded() Function
How to insert spaces/tabs in text using HTML/CSS?
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to create footer to stay at the bottom of a Web page?
How to set the default value for an HTML <select> element ?
How do you run JavaScript script through the Terminal?