Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    NODENode.js

    Runtime and core tooling

    • What is Node.js?
    • CommonJS and ES modules
    • npm and package.json
    • process and command-line apps

    Async I/O and events

    • Event loop: callbacks to async/await
    • Files and paths with fs/promises
    • EventEmitter
    • Streams and backpressure

    HTTP and APIs

    • Your first HTTP server
    • Routing and JSON bodies
    • Build a tiny router and middleware chain
    • REST: resources and status codes
    • Validation and error handling

    Production: security, testing and deployment

    • Authentication basics with crypto
    • Configuration and environment secrets
    • Testing with assert and node:test
    • API security fundamentals
    • Project: tasks REST API and deployment
    Node.js

    Async I/O and events · Lesson 8 of 18

    Streams and backpressure

    Process large data chunk by chunk instead of buffering it all in memory.

    12 minutes2 games

    readFile must buffer an entire file. A stream moves small chunks, starting work early while keeping memory bounded. Readables produce, Writables consume, Transforms modify, and pipeline connects them with error handling and cleanup.

    Readable chunks

    Transform

    Backpressure

    Writable

    Node.js
    const { Readable, Transform, Writable } = require("node:stream")
    const { pipeline } = require("node:stream/promises")
    
    async function main() {
      const out = []
      await pipeline(
        Readable.from(["sea", "code"]),
        new Transform({ transform(chunk, _enc, cb) { cb(null, chunk.toString().toUpperCase()) } }),
        new Writable({ write(chunk, _enc, cb) { out.push(chunk.toString()); cb() } })
      )
      console.log(out.join(" "))
    }
    main().catch(console.error)

    Backpressure means a consumer tells a producer to slow down when its buffer fills. pipe and pipeline manage it. If manually writing and write() returns false, wait for drain. For files use createReadStream and createWriteStream.

    Important

    Prefer pipeline over a raw .pipe() chain in production when you need one Promise that catches errors from every stage and closes the rest. Never assume chunk boundaries match lines or JSON records.

    Quick question

    Why is a stream better for a 10GB file?

    Interview question

    What is backpressure?

    Exercise

    Use Readable.from and consume sea, code, academy with for-await, joining by dashes. Print sea-code-academy.

    Expected output: sea-code-academy

    Node.js
    const { Readable } = require("node:stream")
    async function main() {
      const parts = []
      const input = Readable.from(["sea", "code", "academy"])
    
      console.log(parts.join("-"))
    }
    main()

    Learn more from

    • Node.js: Streamsnodejs.org
    • WHATWG: Streams Standardstreams.spec.whatwg.org

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousEventEmitterNextYour first HTTP server
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.