The writable.writableLength property is an inbuilt application of stream module which is used to check the number of bytes in the queue that is ready to be written.
Syntax:
writable.writableLength
Return Value: This property returns the number of bytes that is ready to write into the queue.
Below examples illustrate the use of writable.writableLength property in Node.js:
Example 1:
// Node.js program to demonstrate the // writable.writableLength 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(); } }); // Calling cork() function writable.cork(); //Writing data writable.write('hi'); // Again writing some data writable.write('GFG'); // Calling writable.writableLength // Property writable.writableLength; |
Output:
5
Example 2:
// Node.js program to demonstrate the // writable.writableLength 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(); } }); // Calling cork() function writable.cork(); //Writing data writable.write('hi'); // Calling uncork() function writable.uncork(); // Again calling cork function writable.cork(); // Again writing some data writable.write('GFG'); // Calling writable.writableLength // Property writable.writableLength; |
Output:
hi 3
Here, the data ‘hi’ is not present in buffer anymore So, the buffer has only 3 bytes present data ‘GFG’ takes 3 bytes.
Reference: https://nodejs.org/api/stream.html#stream_writable_writablelength
Recommended Posts:
- Nodejs | Automatic restart NodeJs server with nodemon
- Node.js | Stream writable.writableFinished Property
- Node.js | Stream writable.writableObjectMode Property
- Node.js | Stream writable.writableHighWaterMark Property
- Node.js | Stream writable.writableCorked Property
- Node.js | Stream writable.writableEnded Property
- Node.js | Stream writable.writable Property
- Node.js | Stream writable.destroyed Property
- Node.js | Stream readable.readable Property
- Node.js | Stream readable.destroyed Property
- Node.js | Stream readable.readableEncoding Property
- Node.js | Stream readable.readableEnded Property
- Node.js | Stream readable.readableFlowing Property
- Node.js | Stream readable.readableHighWaterMark Property
- Node.js | Stream readable.readableLength Property
- Node.js | Stream readable.readableObjectMode Property
- Nodejs - Connect MongoDB with Node app using MongooseJS
- Cowsay in Nodejs using Requests library
- Nodejs | Web Crawling using Cheerio
- Web-Socket in NodeJS
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.

