Node.js Stream writable.writableObjectMode Property
Last Updated :
12 Oct, 2021
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:
const stream = require( 'stream' );
const writable = new stream.Writable({
objectMode: true ,
write: function (chunk, encoding, next) {
console.log(chunk.toString());
next();
}
});
writable.write( 'GfG' )
writable.writableObjectMode;
|
Output:
GfG
true
Example 2:
const stream = require( 'stream' );
const writable = new stream.Writable({
write: function (chunk, encoding, next) {
console.log(chunk.toString());
next();
}
});
writable.write( 'GfG' )
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
Share your thoughts in the comments
Please Login to comment...