Open In App

Node.js request.writableEnded Property

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

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




// Node.js program to demonstrate the 
// request.writableEnded property 
  
// Using require to access http module 
const { get } = require('http'); 
  
// Setting host server url 
const options = { host: 'www.geeksforgeeks.org' }; 
  
// Requesting from geeksforgeeks server 
const request = get(options); 
  
console.log("writableEnded:", request.writableEnded);
  
request.end(); 
  
console.log("writableEnded:", request.writableEnded);
  
request.once('response', (res) => { 
  
    // Printing the requestrelated data 
    console.log("Status:", res.statusCode, res.statusMessage); 
    console.log("Writable:", request.socket.writable); 
    console.log("Readable:", request.socket.readable); 
      
    console.log("writableEnded:", request.writableEnded);
  
    // Printing address and port after getting response 
    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


Last Updated : 23 Sep, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads