Skip to content
Related Articles

Related Articles

Improve Article

Node.js Stream writable.writable Property

  • Last Updated : 12 Oct, 2021

The writable.writable property is an inbuilt application programming interface of Stream module which is used to check the writable.write() method is safe to call or not.

Syntax:

writable.writable 

Return Value: It returns true if it is safe to call writable.write() method otherwise returns false.

Below examples illustrate the use of writable.writable property in Node.js:

Example 1:






// Node.js program to demonstrate the     
// writable.writable Property
  
// Accessing stream module
const stream = require('stream');
  
// Creating a stream and creating 
// a write function
const writable = new stream.Writable({
  
  // Write function with its 
  // parameters
  write: function(chunk, encoding, next) {
  
    // Converting the chunk of
    // data to string
    console.log(chunk.toString());
    next();
  }
});
  
// Writing data
writable.write('hi');
  
// Again writing some data
writable.write('GFG');
  
// Calling writable.writable
// Property
writable.writable;

Output:

hi
GFG
true

Example 2:




// Node.js program to demonstrate the     
// writable.writable Property
  
// Accessing stream module
const stream = require('stream');
  
// Creating a stream and creating 
// a write function
const writable = new stream.Writable({
  
  // Write function with its 
  // parameters
  write: function(chunk, encoding, next) {
  
    // Converting the chunk of
    // data to string
    console.log(chunk.toString());
    next();
  }
});
  
// Writing data
writable.write('hi');
  
// Again writing some data
writable.write('GFG');
  
// Calling end() method
writable.end();
  
// Calling writable.writable
// Property
writable.writable;

Output:

hi
GFG
false

In the above example the output is false because the writable.end() method is called before calling the writable.writable property, so it is not safe to call writable.write() method so the output is false.

Reference: https://nodejs.org/api/stream.html#stream_writable_writable




My Personal Notes arrow_drop_up
Recommended Articles
Page :