Computer >> Computer tutorials >  >> Programming >> Javascript

Stream writable.writableObjectMode Property in Node.js


The writable.writableObjectMode property is used for getting the objectMode property of the given writable Stream. The property will return 'true' if the object mode is set, else 'false' will be returned.

Syntax

writeable.writableObjectMode

Example

Create a file with name – writableObjectMode.js and copy the below code snippet. After creating file, use the following command to run this code as shown in the example below −

node writableObjectMode.js

writableObjectMode.js

// Program to demonstrate writable.writableObjectMode property
// Importing the stream module
const stream = require('stream');

// Setting the objectMode to true
objectMode: true

// Creating a data stream with writable
const writable = new stream.Writable({
   // Writing the data from stream
   write: function(chunk, encoding, next) {
      // Converting the data chunk to be displayed
      console.log(chunk.toString());
      next();
   }
});

// Writing data - Not in the buffer queue
writable.write('Welcome to TutorialsPoint !');
writable.write('SIMPLY LEARNING ');

// Printing the length of the queue data
console.log(writable.writableObjectMode == true);

Output

C:\home\node>> node writableObjectMode.js
Welcome to TutorialsPoint !
SIMPLY LEARNING
true

Example

Let's take a look at one more example.

// Program to demonstrate writable.writableObjectMode property
// Importing the stream module
const stream = require('stream');

// Creating a data stream with writable
const writable = new stream.Writable({
   // Writing the data from stream
   write: function(chunk, encoding, next) {
      // Converting the data chunk to be displayed
      console.log(chunk.toString());
      next();
   }
});

// Writing data - Not in the buffer queue
writable.write('Welcome to TutorialsPoint !');
writable.write('SIMPLY LEARNING ');

// Printing the length of the queue data
console.log(writable.writableObjectMode);

Output

C:\home\node>> node writableObjectMode.js
Welcome to TutorialsPoint !
SIMPLY LEARNING
undefined

Default value is undefined.