+1 vote
in NodeJS Essentials by

What is Streams in Node.js?

1 Answer

0 votes
by

Streams are pipes that let you easily read data from a source and pipe it to a destination. Simply put, a stream is nothing but an EventEmitter and implements some specials methods. Depending on the methods implemented, a stream becomes Readable, Writable, or Duplex (both readable and writable).

For example, if we want to read data from a file, the best way to do it from a stream is to listen to data event and attach a callback. When a chunk of data is available, the readable stream emits a data event and your callback executes. Take a look at the following snippet:

Related questions

+1 vote
asked May 31, 2020 in NodeJS Essentials by Robindeniel
+1 vote
asked May 30, 2020 in NodeJS Essentials by SakshiSharma
...