Node.js | Stream readable.readableObjectMode Property

The readable.readableObjectMode property in a Readable Stream that is used to check the objectMode of the stream.

Syntax:

readable.readableObjectMode

Return Value: It returns the Boolean value.

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

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the     
// readable.readableObjectMode Property
   
// Accessing readable stream module
const Readable = require('readable-stream').Readable;
  
// Constructing readable stream and
// setting the objectMode value
const readable = Readable({objectMode: true});
  
// Defining ._read method
readable._read = () => {};
  
// Instructions for reading data
readable.on('readable', () => {
  let chunk;
  
  // Using while loop and calling
  // read method with parameter
  while (null !== (chunk = readable.read(4))) {
  
    // Displaying the chunk
    console.log(`read: ${chunk}`);
  }
});
  
// Calling readableObjectMode
// Property
readable.readableObjectMode;
console.log("objectMode is true!!");

chevron_right


Output:

objectMode is true!!

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the     
// readable.readableObjectMode Property
   
// Accessing readable stream module
const Readable = require('readable-stream').Readable;
  
// Constructing readable stream and
// setting the objectMode value
const readable = Readable({objectMode: false});
  
// Defining ._read method
readable._read = () => {};
  
// Instructions for reading data
readable.on('readable', () => {
  let chunk;
  
  // Using while loop and calling
  // read method with parameter
  while (null !== (chunk = readable.read(4))) {
  
    // Displaying the chunk
    console.log(`read: ${chunk}`);
  }
});
  
// Calling readableObjectMode
// Property
readable.readableObjectMode;
console.log("objectMode is false!!");

chevron_right


Output:

objectMode is false!!

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




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.