1. Stream factories
createReadStream and createWriteStream open files as streams that move data in small chunks.
import { createReadStream, createWriteStream } from "node:fs";Typorithm · medium
Step 1 of 8 · intro card
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.
createReadStream / createWriteStream move data in chunks.
pipe forwards chunks and manages backpressure for you.
Streams use constant memory; readFile loads the whole file.
import { createReadStream, createWriteStream } from "node:fs";
createReadStream("big.csv").pipe(createWriteStream("copy.csv"));Connect each part of the code to the concept before you type.
createReadStream and createWriteStream open files as streams that move data in small chunks.
import { createReadStream, createWriteStream } from "node:fs";A readable stream emits the file in chunks instead of loading it all into memory at once.
createReadStream("big.csv")pipe connects a readable to a writable, forwarding each chunk and handling backpressure automatically.
.pipe(The writable stream receives chunks and writes them to disk as they arrive.
createWriteStream("copy.csv")Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.