Node.js http.ClientRequest.writableFinished API
The http.ClientRequest.writableFinished is an inbuilt application programming interface of class ClientRequest within http module which is used to check if all the data has been flushed or not.
Syntax:
const request.writableEnded
Parameters: This API does not accept any argument as parameter.
Return Value : This method returns true if and only if all the data has been flushed.
Example 1:
index.js
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);
if (req.writableFinished)
console.log( 'all data has been flushed' )
else
console.log( 'all data has not been flushed' )
process.exit(0)
});
|
Output:
Last Updated :
08 Apr, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...