Node.js http.server.timeout Property
The http.server.timeout is an inbuilt application programming interface of class Server within the HTTP module which is used to get the default Timeout value in milliseconds. In Node.js, the 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
const http = require( 'http' );
const PORT = process.env.PORT || 3000;
const httpServer = http.createServer(
function (request, response) {
const value = response.socket;
response.end( "socket buffersize : "
+ value.bufferSize, 'utf8' , () => {
console.log( "Displaying the result..." );
httpServer.close(() => {
console.log( "Server is closed" )
})
});
});
httpServer.listen(PORT, () => {
console.log( "Server is running at port 3000..." );
});
const v = httpServer.timeout
console.log( 'Default time out value :- ' + v)
|
Run the index.js file using the 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
const http = require( 'http' );
const http2Handlers = (request, response) => {
const value = response.socket;
response.end( "socket local address : "
+ value.localAddress, 'utf8' , () => {
console.log( "Displaying the result..." );
httpServer.close(() => {
console.log( "Server is closed" )
})
});
};
const httpServer = http.createServer(
http2Handlers).listen(3000, () => {
console.log( "Server is running at port 3000..." );
});
const v = httpServer.timeout
console.log( 'Default time out value :- ' + v)
|
Run the index.js file using the 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
Last Updated :
06 Apr, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...