I am learning node js and I am at the sterams module.
I have below query - What is the difference between these two statements.
const {Readable} = require("stream")
and
const Readable = require("stream")
Below Code Snippet works . Means data is emitted by Read Stream and end of stream is also raised.
But when const {Readable}
is converted to const Readable
, it stops working
Can anybody help why this behaviour ?
const {Readable} = require("stream"); // changing const Readable = require("stream") doesn't work
const createReadStream = () => {
const data = ["one","two","three"];
return new Readable({
read(){
if (data.length === 0) {
console.log('data ended');
this.push(null);
} else{
console.log('reading data');
this.push(data.shift());
}
}
});
}