Node.js Streams: Everything you need to know - Deepstash
Metaverse

Learn more about computerscience with this collection

Find out the challenges it poses

Learn about the potential impact on society

Understanding the concept of Metaverse

Metaverse

Discover 76 similar ideas in

It takes just

11 mins to read

What exactly are streams?

Streams are collections of data — just like arrays or strings. The difference is that streams might not be available all at once, and they don’t have to fit in memory. This makes streams really powerful when working with large amounts of data, or data that’s coming from an external source one chunk at a time.

However, streams are not only about working with big data. They also give us the power of composability in our code. Just like we can compose powerful linux commands by piping other smaller Linux commands, we can do exactly the same in Node with streams.

11

75 reads

Streams 101

There are four fundamental stream types in Node.js: Readable, Writable, Duplex, and Transform streams.

  • A readable stream is an abstraction for a source from which data can be consumed. An example of that is the fs.createReadStream method.
  • A writable stream is an abstraction for a destination to which data can be written. An example of that is the fs.createWriteStream method.
  • A duplex streams is both Readable and Writable. An example of that is a TCP socket.
  • Transform streams are basically a duplex stream that can be used to modify or transform the data as it is written and read.

9

56 reads

Stream events

The most important events on a readable stream are:

  • The data event, which is emitted whenever the stream passes a chunk of data to the consumer
  • The end event, which is emitted when there is no more data to be consumed from the stream.

9

39 reads

Paused and Flowing Modes of Readable Streams

Readable streams have two main modes that affect the way we can consume them: 

  • They can be either in the paused mode 
  • Or in the flowing mode.

9

47 reads

Implementing Streams

When we talk about streams in Node.js, there are two main different tasks:

  • The task of implementing the streams.
  • The task of consuming them.

8

35 reads

Implementing a Writable Stream

This write method takes three arguments.

  • The chunk is usually a buffer unless we configure the stream differently.
  • The encoding argument is needed in that case, but usually we can ignore it.
  • To signal a failure, call the Callback with an error object.

8

32 reads

Implementing Duplex/Transform Streams

The readable and Writable sides of a duplex stream operate completely independently from one another. A transform stream is the more interesting duplex stream because its output is computed from its input. 

For a transform stream, we don’t have to implement the read or write methods, we only need to implement a transform method, which combines both of them. It has the signature of the write method and we can use it to push data as well. Here’s an example duplex stream which

8

34 reads

CURATED BY

isaactu

Telecommunications researcher

More like this

stash-superman-illustration

Explore the World’s

Best Ideas

200,000+ ideas on pretty much any topic. Created by the smartest people around & well-organized so you can explore at will.

An Idea for Everything

Explore the biggest library of insights. And we've infused it with powerful filtering tools so you can easily find what you need.

Knowledge Library

Powerful Saving & Organizational Tools

Save ideas for later reading, for personalized stashes, or for remembering it later.

# Personal Growth

Take Your Ideas

Anywhere

Organize your ideas & listen on the go. And with Pro, there are no limits.

Listen on the go

Just press play and we take care of the words.

Never worry about spotty connections

No Internet access? No problem. Within the mobile app, all your ideas are available, even when offline.

Get Organized with Stashes

Ideas for your next work project? Quotes that inspire you? Put them in the right place so you never lose them.

Join

2 Million Stashers

4.8

5,740 Reviews

App Store

4.7

72,690 Reviews

Google Play

Sean Green

Great interesting short snippets of informative articles. Highly recommended to anyone who loves information and lacks patience.

samz905

Don’t look further if you love learning new things. A refreshing concept that provides quick ideas for busy thought leaders.

Shankul Varada

Best app ever! You heard it right. This app has helped me get back on my quest to get things done while equipping myself with knowledge everyday.

Ashley Anthony

This app is LOADED with RELEVANT, HELPFUL, AND EDUCATIONAL material. It is creatively intellectual, yet minimal enough to not overstimulate and create a learning block. I am exceptionally impressed with this app!

Giovanna Scalzone

Brilliant. It feels fresh and encouraging. So many interesting pieces of information that are just enough to absorb and apply. So happy I found this.

Ghazala Begum

Even five minutes a day will improve your thinking. I've come across new ideas and learnt to improve existing ways to become more motivated, confident and happier.

Jamyson Haug

Great for quick bits of information and interesting ideas around whatever topics you are interested in. Visually, it looks great as well.

Laetitia Berton

I have only been using it for a few days now, but I have found answers to questions I had never consciously formulated, or to problems I face everyday at work or at home. I wish I had found this earlier, highly recommended!

Read & Learn

20x Faster

without
deepstash

with
deepstash

with

deepstash

Access to 200,000+ ideas

Access to the mobile app

Unlimited idea saving & library

Unlimited history

Unlimited listening to ideas

Downloading & offline access

Personalized recommendations

Supercharge your mind with one idea per day

Enter your email and spend 1 minute every day to learn something new.

Email

I agree to receive email updates