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