to a promise
. A Node.js stream is fundamentally an event emitter with 3 events:
- data: a new chunk of data is available
- error: an error occurred
- end: the stream is finished
The part of this question that I’ve seen a lot of developers struggle with is the concept of reactive programming. Given an event emitter, you cannot control the event emitter. You can only react to what events the event emitter sends you. Many developers struggle because they try to treat an event emitter as an event queue and try to figure out how they can write a while loop to pull events from the event emitter.
Imperative programming means you are responsible for pulling an event off of a queue. Reactive programming means you register a callback