Typorithm · medium

Streams & pipe

streams-pipenodejsstreamspipebackpressure
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Streams & pipe

0%

File System & Streams

createReadStream and createWriteStream move a file in small chunks; pipe wires the readable into the writable. Streams use constant memory and apply backpressure, so they beat readFile for files too large to fit in RAM.

Streams process a file chunk by chunk rather than loading it whole, so memory stays flat no matter how large the file grows.

pipe connects a readable stream to a writable one: it forwards every chunk and pauses the source when the destination falls behind — that is backpressure.

readFile must hold the entire file in memory at once; for multi-gigabyte files that exhausts RAM, which is exactly why streaming with pipe is the idiomatic choice.

01

createReadStream / createWriteStream move data in chunks.

02

pipe forwards chunks and manages backpressure for you.

03

Streams use constant memory; readFile loads the whole file.

import { createReadStream, createWriteStream } from "node:fs";
createReadStream("big.csv").pipe(createWriteStream("copy.csv"));

Read the implementation

Connect each part of the code to the concept before you type.

1. Stream factories

createReadStream and createWriteStream open files as streams that move data in small chunks.

import { createReadStream, createWriteStream } from "node:fs";

2. Readable stream

A readable stream emits the file in chunks instead of loading it all into memory at once.

createReadStream("big.csv")

3. Wire them together

pipe connects a readable to a writable, forwarding each chunk and handling backpressure automatically.

.pipe(

4. Writable stream

The writable stream receives chunks and writes them to disk as they arrive.

createWriteStream("copy.csv")

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Streams & pipe: Lesson & Practice · Typorithm | ApplyDjinn