Node.js Stream readable.destroyed Property
The readable.destroyed property is an inbuilt application programming interface of Stream module which is used to check the readable.destroy() function is being called or not.
Syntax:
readable.destroyed
Return Value: It returns true if readable.destroy() method is being called otherwise returns false.
Below examples illustrate the use of readable.destroyed property in Node.js:
Example 1:
// Node.js program to demonstrate the // readable.destroyed Property // Include fs moduleconst fs = require("fs"); // Constructing readable streamconst readable = fs.createReadStream("input.txt"); // Instructions for reading datareadable.on('readable', () => { let chunk; // Using while loop and calling // read method with parameter while (null !== (chunk = readable.read())) { // Displaying the chunk console.log(`read: ${chunk}`); }}); // Handling error eventreadable.on('error', err => { console.log(err);}); // Calling destroy method// with parameterreadable.destroy('error'); // Displays that the stream is // destroyedconsole.log("Stream destroyed"); // Calling readable.destroyed// Propertyreadable.destroyed; |
Output:
Stream destroyed true error
Example 2:
// Node.js program to demonstrate the // readable.destroyed Property // Include fs moduleconst fs = require("fs"); // Constructing readable streamconst readable = fs.createReadStream("input.txt"); // Instructions for reading datareadable.on('readable', () => { let chunk; // Using while loop and calling // read method with parameter while (null !== (chunk = readable.read())) { // Displaying the chunk console.log(`read: ${chunk}`); }}); // Displays that the stream is // destroyedconsole.log("Program completed!!"); // Calling readable.destroyed// Propertyreadable.destroyed; |
Output:
Program completed!! false read: hello
So, here readable.destroy() method is not called before readable.destroyed property so it returns false.
Reference: https://nodejs.org/api/stream.html#stream_readable_destroyed


