The request.writableEnded (Added in v12.9.0) property is an inbuilt property of the ‘http’ module which returns true after request.end() has been called. This property does not indicate whether the data has been flushed, for this use request.writableFinished instead.
In order to get a response and a proper result, we need to import ‘http’ module.
Syntax:
const http = require('http');
Syntax:
request.writableEnded
Parameters: This property does not accept any parameters.
Return Value <Boolean>: It returns true after request.end() has been called.
The below examples illustrate the use of request.writableEnded property in Node.js.
Example: Filename: index.js
const { get } = require( 'http' );
const options = { host: 'www.geeksforgeeks.org' };
const request = get(options);
console.log( "writableEnded:" , request.writableEnded);
request.end();
console.log( "writableEnded:" , request.writableEnded);
request.once( 'response' , (res) => {
console.log( "Status:" , res.statusCode, res.statusMessage);
console.log( "Writable:" , request.socket.writable);
console.log( "Readable:" , request.socket.readable);
console.log( "writableEnded:" , request.writableEnded);
console.log(`IP address of geeksforgeeks is`,
` ${request.socket.localAddress}.`);
console.log(`Its port is ${request.socket.localPort}.`);
});
|
Run index.js file using the following command:
node index.js
Output:
writableEnded: true
writableEnded: true
Status: 301 Moved Permanently
Writable: true
Readable: true
writableEnded: true
IP address of geeksforgeeks is 192.168.43.207.
Its port is 64596
Reference: https://nodejs.org/api/http.html#http_request_writableended