Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Node.js Stream writable.writableObjectMode Property

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The writable.writableObjectMode property in Stream module is used to get the object mode value of the Writable stream.

Syntax:

writable.writableObjectMode 

Return Value: It returns true if the objectMode is set to true otherwise returns false.

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

Example 1:




// Node.js program to demonstrate the     
// writable.writableObjectMode Property
   
// Accessing stream module
const stream = require('stream');
   
// Creating a stream and creating 
// a write function
const writable = new stream.Writable({
   
  // setting value of objectMode
  objectMode: true,
   
  // 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('GfG')
   
// Calling writable.writableObjectMode 
// Property
writable.writableObjectMode;

Output:

GfG
true

Example 2:




// Node.js program to demonstrate the     
// writable.writableObjectMode 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('GfG')
   
// Calling writable.writableObjectMode 
// Property
writable.writableObjectMode;

Output

GfG
false

Here, the objectMode is not set so, by default it is set to false.

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


My Personal Notes arrow_drop_up
Last Updated : 12 Oct, 2021
Like Article
Save Article
Similar Reads
Related Tutorials