---
title: "Discussion on \"A guide to reading and writing Node.js streams\" | Hashnode"
description: "Discussion on \"A guide to reading and writing Node.js streams\". By the end of this guide, you will have a deep understanding of how streams work, including creating and managing readable and writable streams, handling ba"
url: "https://hashnode.com/posts/a-guide-to-reading-and-writing-nodejs-streams/668fd751e5d695eed5680b4d"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [A guide to reading and writing Node.js streams](https://blog.platformatic.dev/a-guide-to-reading-and-writing-nodejs-streams?utm_source=hashnode&utm_medium=feed)

By the end of this guide, you will have a deep understanding of how streams work, including creating and managing readable and writable streams, handling ba

Jul 11, 2024 · 13 min read · blog.platformatic.dev  
Read the article

-   [#nodejs](https://hashnode.com/tag/nodejs)
-   [#nodejs-streams](https://hashnode.com/tag/nodejs-streams)
-   [#streams](https://hashnode.com/tag/streams)
-   [#platformatic](https://hashnode.com/tag/platformatic)

## Written by

[Matteo Collina](https://hashnode.com/@matteocollina)

@matteocollina

  
[View profile](https://hashnode.com/@matteocollina)

Open Sourcerer, Node.js TSC member, Fastify Lead Maintainer

## Responses 6

Markdown supported · ⌘↵ to post

[Emma Raducanu](https://hashnode.com/@raducanue70)

[Aug 16, 2024](https://hashnode.com/posts/a-guide-to-reading-and-writing-nodejs-streams/668fd751e5d695eed5680b4d/comment/66bf7c034758db5019603d3e)

I NEED A HACKER TO RECOVER MY LOST CRYPTOS VISIT \[ ROCKET SPEED RECOVERY HACKER \]

My name is Emma Raducanu and I am from Toronto, Canada well known as a Professional Tennis Player. Have you fallen victim to a Ponzi scheme or are you having problems accessing your bitcoin wallet? For a 100% guarantee on the return of your wallet and any lost money, get in touch with ROCKET SPEED RECOVERY HACKER. In addition, ROCKET SPEED RECOVERY HACKER can help you with phone hacking, iCloud breaches, YouTube breaches, removing criminal records, and enhancing your university grades. Captain ROCKET SPEED RECOVERY HACKER has been helping people and businesses secure and retrieve stolen digital currencies like Eth and Bitcoin for years. contact them at...

WhatsApp .. +1 (269) 369–5436 Email… rocketspeedrecoveryhacker@seznam.cz Telegram..[t.me/rocketspeedrecoveryhacker](http://t.me/rocketspeedrecoveryhacker)

[Jackson David](https://hashnode.com/@jackson943)

[Aug 13, 2024](https://hashnode.com/posts/a-guide-to-reading-and-writing-nodejs-streams/668fd751e5d695eed5680b4d/comment/66baec5fe2f22beb3be3a55a)

i live in Canada a friend introduces me to blank atm card which i got from Davidwilson hackers, i believe him so well not like scammers out there i have withdrew $50000 with this card so i decided to share a testimony if you are interested contact him now for Financial Solutions Davidwilson2284@gmail.com

[Esten Grove](https://hashnode.com/@Esten)

[Aug 2, 2024](https://hashnode.com/posts/a-guide-to-reading-and-writing-nodejs-streams/668fd751e5d695eed5680b4d/comment/66ad5f433f8465a4805c5432)

Really great article. Would love for an in depth article on async generators. Saw a library recently using them for streams & it seemed very concise. Would be interested to leer more.

[Stasa Stanisic](https://hashnode.com/@stasas)

[Jul 20, 2024](https://hashnode.com/posts/a-guide-to-reading-and-writing-nodejs-streams/668fd751e5d695eed5680b4d/comment/669bc4c5e7c7f0d1d346a3c6)

Thank you for a great streams overview!

How would you write out the correct version of HTTP stream example with stream/promises pipeline, pass res as last parameter? And for fastify, reply.send?

[Matteo Collina](https://hashnode.com/@matteocollina)

[Jul 25, 2024](https://hashnode.com/posts/a-guide-to-reading-and-writing-nodejs-streams/668fd751e5d695eed5680b4d/comment/669bc4c5e7c7f0d1d346a3c6#reply-66a223b1f67fe113f8fcb4d2)

use `@fastify/static` :). Don't stream files directly because there are infinite edge cases that will inevitably result in a security issues in your server.

[Stasa Stanisic](https://hashnode.com/@stasas)

[Jul 25, 2024](https://hashnode.com/posts/a-guide-to-reading-and-writing-nodejs-streams/668fd751e5d695eed5680b4d/comment/669bc4c5e7c7f0d1d346a3c6#reply-66a22736f9ee50415797da53)

[Matteo Collina](https://hashnode.com/@matteocollina) Thanks for the reply! Yes, understood for static files which can be directly served, but I was thinking more of the case when there is a pipeline - reading file then transforming and finally sending as a response...

[Matteo Collina](https://hashnode.com/@matteocollina)

[Jul 25, 2024](https://hashnode.com/posts/a-guide-to-reading-and-writing-nodejs-streams/668fd751e5d695eed5680b4d/comment/669bc4c5e7c7f0d1d346a3c6#reply-66a2459182434a49dc324bcc)

[Stasa Stanisic](https://hashnode.com/@stasas) you can just call `reply.send(stream)` or `return stream` in your Fastify route. Using barebone HTTP, you should do `pipeline(a, b, c, res, (err) => { ... })`.

[Sarfraz Ashrafi](https://hashnode.com/@MohammedSarfraz)

[Jul 20, 2024](https://hashnode.com/posts/a-guide-to-reading-and-writing-nodejs-streams/668fd751e5d695eed5680b4d/comment/669b9d40ec44bd003c3b10e1)

thank you mate informative

[Priyankar Pal](https://hashnode.com/@priyankarpal1)

[Jul 20, 2024](https://hashnode.com/posts/a-guide-to-reading-and-writing-nodejs-streams/668fd751e5d695eed5680b4d/comment/669b35d2ee40ae2f2205fd0b)

Well written article. How did you design the diagram?

[Matteo Collina](https://hashnode.com/@matteocollina)

[Jul 25, 2024](https://hashnode.com/posts/a-guide-to-reading-and-writing-nodejs-streams/668fd751e5d695eed5680b4d/comment/669b35d2ee40ae2f2205fd0b#reply-66a2223530807b6f84e024a3)

We have an amazing designer at platformatic :).

[Jason Jiang](https://hashnode.com/@jasonjiang7)

[Jul 18, 2024](https://hashnode.com/posts/a-guide-to-reading-and-writing-nodejs-streams/668fd751e5d695eed5680b4d/comment/6698f792d8d1c8446fa805d5)

Thanks for the great guide, and I was confused with the Writeable demo: Why the "wait drain" was logged after only one HELLO is logged to stdout, I assume the buffer was empty after the first HELLO logged, the 2nd HELLO should also be logged before the first "wait drain", not sure where did i misunderstood, is this because the stdout.write is async, after calling the "cb", the "hello" in the buffer will be removed?

[Matteo Collina](https://hashnode.com/@matteocollina)

[Jul 25, 2024](https://hashnode.com/posts/a-guide-to-reading-and-writing-nodejs-streams/668fd751e5d695eed5680b4d/comment/6698f792d8d1c8446fa805d5#reply-66a2236196271f659e5801b5)

Good spot! The buffer is flushed on first write. Because the `cb` will be called after an event loop turn (it's async!), we need to wait for `drain`. To counteract this effect there are cork() and uncork(). They are used to send out the http headers for example.

[Vineeth Kasula](https://hashnode.com/@vineethKasula)

[Jul 12, 2024](https://hashnode.com/posts/a-guide-to-reading-and-writing-nodejs-streams/668fd751e5d695eed5680b4d/comment/66913571ca3928be95d3e06e)

Thanks, This is really helpful
