Open In App

Node.js Stream writable.writableHighWaterMark Property

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

The writable.writableHighWaterMark property is an inbuilt application programming interface of stream module which is used to check the highWaterMark value which was passed while creating the Writable.

Syntax:

writable.writableHighWaterMark

Return Value: It returns the value of highwatermark if it is set otherwise returns the default value.

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

Example 1:




// Node.js program to demonstrate the     
// writable.writableHighWaterMark 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('hi');
  
// Again writing some data
writable.write('GFG');
  
// Calling writable.writableHighWaterMark 
// Property
writable.writableHighWaterMark;


Output:

hi
GFG
16384

Here, the default value is returned.

Example 2:




// Node.js program to demonstrate the     
// writable.writableHighWaterMark Property
  
// Accessing stream module
const stream = require('stream');
  
// Creating a stream and setting the value
// of the highWaterMark
const writable = new stream.Writable({
    highWaterMark: 1234
});
  
// Calling writable.writableHighWaterMark 
// Property
writable.writableHighWaterMark;


Output:

1234

Here, the value of highWaterMark which was set while creating Writable stream is returned.

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



Last Updated : 12 Oct, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads