Node.js http.ClientRequest.setNoDelay() Method
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
// Node.js program to demonstrate the // request.setNoDelay() method// Importing http moduleconst http = require('http');// Create an HTTP serverconst server = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('okay');});// Now that server is runningserver.listen(3000, '127.0.0.1', () => { // Make a request const options = { port: 3000, host: '127.0.0.1', headers: { 'Connection': 'Upgrade', 'Upgrade': 'websocket' } }; // Getting client request const req = http.request(options); req.host = '127.0.0.1' // Setting the nodelay for the socket // by using setNoDelay method req.setNoDelay(true); // Display the result 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
// Node.js program to demonstrate the // request.setNoDelay() method// Importing http moduleconst http = require('http');// Create an HTTP serverhttp.createServer((req, res) => {}).listen(3000, '127.0.0.1', () => { // Getting client request const req = http.request({ port: 3000, host: '127.0.0.1', }); // Setting the nodelay for the socket // by using setNoDelay method req.setNoDelay(true); // Display the result 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


