Roadmaps / JavaScript / Phase 2
Phase 2 of 4 · Study weeks 5-8
Modules, streams, workers and correct data
This phase makes the second checkpoint possible: a service that reads untrusted bodies safely, keeps CPU work off the event loop and ships as a package other code can import.
Topics every week
- Week 58 h
- ES modules and CommonJS interop
- The
exportsmap and conditions - Cycles and top-level
await - The dual package hazard
Hand inA package consumed from ESM, CommonJS and a bundler, with a three-way test matrix
- Week 68 h
- Web Streams and Node streams
pipelineand error cleanup- Backpressure
- Byte caps and decompression limits
Hand inA streaming reader that cuts a 1 GB response at 2 MB with flat memory
- Week 78 h
- Worker threads and message passing
- Structured clone and transfer
SharedArrayBufferandAtomics- When threads lose to the main thread
Hand inA worker pool with a benchmark that shows where a worker starts to win
- Week 88 h
- Floating point,
BigIntand money - Unicode, normalisation and
Intl Temporalfor dates and zonesJSONedge cases
Hand inCheckpoint 2, plus a correctness audit of 10 date, money and text cases
- Floating point,
Practice projects
- Practice 1, the consumer matrix (Week 5): ship a small package and load it from an ES module, a CommonJS file and a bundler. Done when: all three pass in CI, and a test proves a deep import that is not in
exportsfails. - Practice 2, the byte cap (Week 6): stream a generated 1 GB body through your reader. Done when: the read stops at 2 MB, RSS grows by under 50 MB over 100 runs, and the fake server sees every socket close.
- Practice 3, worker break-even (Week 7): parse HTML of growing size on the main thread and in a worker. Done when: a table shows the size where the worker wins, and says what copying and transfer cost.
- Optional, a ring buffer on
SharedArrayBuffer: pass numbers between threads withAtomics. Done when: a stress test shows no lost or duplicated values in 10 million messages.
GitHub repos to study
Existence, last commit and README notices were checked on 22 Nov 2026 by shallow clone. Every repository below had a commit in the last six months. Archive status comes from the README, not from the GitHub setting, so look again before you rely on one.
| Repo | What to read | Week |
|---|---|---|
| nodejs/undici | How fetch, redirects and body streams are implemented | 6 |
| whatwg/streams | The standard and its reference implementation, for backpressure | 6 |
| nodejs/node | lib/ streams and worker_threads code | 6 |
| piscinajs/piscina | A worker pool: queueing, task transfer, cancellation | 7 |
| js-temporal/temporal-polyfill | A reference for correct date handling where Temporal is missing | 8 |
Milestone checkpoint
Extend the fetcher into Checkpoint 2. Read bodies as a stream with the 2 MB cap and the redirect limit, move HTML parsing behind a worker pool interface, and publish the package with an exports map. Add the redirect loop and the gzip bomb to the fake server. Hand in the byte-cap measurements, the matrix results and ADR-3 (stream cap and where it is enforced) and ADR-4 (worker pool or main thread, with the break-even number).
Check yourself
Answer each question in your head first, then open it to check.
What does an
exportsmap do, and what goes wrong without one?It lists the public entry points and the conditions (import,require) for each. Without it, deep imports become part of your API, and a mixed consumer can load two copies of the package.What is backpressure, and what happens to memory without it?
The consumer tells the producer to pause. Without it, a fast producer queues data in memory until the process runs out.When is a worker thread slower than the main thread?
For small tasks, where starting the worker and copying data costs more than the work. Transferring buffers or sharing memory removes the copy.Why does
0.1 + 0.2differ from0.3, and how do you store money?Numbers are binary floating point, and 0.1 has no exact binary form. Store money as integers in the smallest unit, or use a decimal library.What does a gzip bomb do, and why is the
Content-Lengthheader no defence?A small compressed body expands to gigabytes. The header describes the compressed size, so count the decompressed bytes as you read.