Node.js http.ClientRequest.setNoDelay() Method
Last Updated :
06 May, 2021
The http.ClientRequest.setNoDelay() is an inbuilt application programming interface of class ClientRequest within HTTP module which is used to set the socket such as delaying of excessive requests while requests are being limited is not desired.
Syntax:
const request.setNoDelay([noDelay])
Parameters: This method takes the Boolean value as a parameter.
Return Value: This method has nothing to return.
Example 1: Filename-index.js
Javascript
const http = require( 'http' );
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type' : 'text/plain' });
res.end( 'okay' );
});
server.listen(3000, '127.0.0.1' , () => {
const options = {
port: 3000,
host: '127.0.0.1' ,
headers: {
'Connection' : 'Upgrade' ,
'Upgrade' : 'websocket'
}
};
const req = http.request(options);
req.host = '127.0.0.1'
req.setNoDelay( true );
console.log( "no delay is set" )
process.exit(0)
});
|
Run the index.js file using the following command:
node index.js
Output:
no delay is set
Example 2: Filename-index.js
Javascript
const http = require( 'http' );
http.createServer((req, res) => {}).listen(3000, '127.0.0.1' , () => {
const req = http.request({
port: 3000,
host: '127.0.0.1' ,
});
req.setNoDelay( true );
console.log( "no delay is set" )
process.exit(0)
});
|
Run the index.js file using the following command:
node index.js
Output:
no delay is set
Reference: https://nodejs.org/dist/latest-v12.x/docs/api/http.html#http_request_setnodelay_nodelay
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...