Most people don't master Node.js — they master Express, or Nest, or whatever framework their first job used. That's a fine way to ship features. It is not the same as understanding the runtime you're standing on, and it's why the same class of bugs (event loop stalls, memory leaks, "why is this callback firing twice") keeps resurfacing for years into a career.
Mastery here means one thing: you can explain and predict what Node.js does without a framework in the way. Everything below builds toward that, in the order it actually needs to be learned.
Stop starting with a framework
If your first Node.js file ever written was app.get('/', ...), you skipped the part that matters. Frameworks hide the request object, the socket, the event loop — exactly the things you need to see to build intuition. Before touching Express or Nest, you should be able to write this without looking it up:
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('hello');
});
server.listen(3000);
If that's unfamiliar, that's the actual starting line — not a tutorial's "Getting Started with Express" section.
Layer 1: the event loop, for real
Everyone can recite "Node.js is single-threaded and non-blocking." Few can answer: in what order do setTimeout, setImmediate, and process.nextTick fire? If you can't answer that with confidence, you don't have the mental model yet — you have the slogan.
setTimeout(() => console.log('timeout'), 0);
setImmediate(() => console.log('immediate'));
process.nextTick(() => console.log('nextTick'));
Promise.resolve().then(() => console.log('promise'));
console.log('sync');
Output, every time: sync, nextTick, promise, timeout, immediate (the timeout/immediate order can flip depending on context, which is itself worth understanding). The reason: microtasks (nextTick, promise callbacks) drain completely between every phase of the event loop, and nextTick has priority over the promise microtask queue. This isn't trivia — it's the reason a recursive process.nextTick call can starve I/O entirely, a real production incident class.
Read the event loop phases (timers, pending callbacks, poll, check, close callbacks) until you can predict ordering for arbitrary combinations of setTimeout, I/O callbacks, and microtasks. This is the single highest-leverage thing you can learn.
Layer 2: the async evolution, and why each step existed
Don't just learn async/await — learn what it replaced and why, or you'll misuse it.
fs.readFile('a.txt', (err, data) => {
if (err) return handleErr(err);
fs.readFile('b.txt', (err, data2) => {
if (err) return handleErr(err);
});
});
Callback hell forced promises. Promises forced .then chains that were still awkward to read sequentially, which is what async/await actually solves — it's sugar over promises, nothing more:
async function read() {
const a = await fs.promises.readFile('a.txt');
const b = await fs.promises.readFile('b.txt');
return [a, b];
}
The mistake this history teaches you to avoid: sequential await when you meant parallel.
const a = await fetchA();
const b = await fetchB();
versus
const [a, b] = await Promise.all([fetchA(), fetchB()]);
The first is twice as slow for no reason. People who "know async/await" but not its history write the first version constantly.
Layer 3: streams, not just fs.readFile
fs.readFile loads the entire file into memory. Fine for a config file, catastrophic for a 4GB video. Streams are how Node.js handles data it can't afford to hold in memory all at once — and they underpin HTTP request/response bodies, file I/O, and compression.
const fs = require('fs');
const zlib = require('zlib');
fs.createReadStream('input.txt')
.pipe(zlib.createGzip())
.pipe(fs.createWriteStream('input.txt.gz'));
Three lines, constant memory usage regardless of file size, backpressure handled for you. Understand readable, writable, duplex, and transform streams, and you understand how Node.js moves bytes — which is most of what a backend does.
Layer 4: the module system, both of them
You will hit require is not defined or Cannot use import outside a module at some point. Knowing why saves an hour of confused searching.
- CommonJS (
require/module.exports) — synchronous, resolved at runtime, the original system. - ES Modules (
import/export) — the standard now, resolved statically, enables tree-shaking.
{ "type": "module" }
That one line in package.json changes how every .js file in the project is parsed. Know the interop rules (a CJS module can't top-level import an ESM one) before you're debugging them at 11pm.
Layer 5: build something with zero dependencies
The fastest way to actually learn the runtime is to reimplement what a framework gives you for free:
- A router that matches paths and methods on top of raw
http.createServer. - A rate limiter using nothing but a
Mapand timestamps. - A tiny key-value store persisted to disk with
fs, with a write-ahead log. - A CLI tool that streams a large CSV, transforms rows, and writes output — using streams, not
readFileSync.
None of these need a single npm install. Each one forces you through a layer above. If you can build a working router in an evening, Express stops being magic and becomes "oh, this is just what I wrote, with a nicer API."
Layer 6: know your escape hatches for CPU-bound work
The event loop only stays fast if nothing blocks it. JSON.parse on a 50MB payload, synchronous crypto, image processing — all of these stall every other request in the process.
const { Worker, isMainThread, parentPort, workerData } = require('worker_threads');
if (isMainThread) {
const worker = new Worker(__filename, { workerData: 42 });
worker.on('message', console.log);
} else {
parentPort.postMessage(workerData * 2);
}
Worker threads run in a separate V8 isolate with their own event loop, communicating via message passing. Knowing when to reach for this — versus child_process, versus just accepting the latency — is a mastery-level judgment call, not a beginner one.
Layer 7: debug and profile without guessing
"Add a console.log and redeploy" is not a debugging strategy. Learn the built-in tools instead:
node --inspect index.js
node --prof index.js && node --prof-process isolate-*.log
--inspect attaches Chrome DevTools to a running Node.js process — real breakpoints, a real call stack, a real heap snapshot. --prof produces a CPU profile you can use to find out which function is actually eating your event loop, instead of guessing. Take a heap snapshot before and after a suspected leak and diff retained objects — this is how memory leaks get found in practice, not by staring at code.
The practice ladder
Reading gets you to "I understand this." Building gets you to "I can predict this." In order:
- Raw
httpserver with manual routing — no framework. - A CLI tool that streams and transforms a large file.
- A WebSocket chat server using the
wspackage directly. - A worker-thread pool that processes a queue of CPU-bound jobs.
- Instrument all of the above with
--inspectand fix one deliberately-introduced memory leak by reading a heap snapshot.
By the time you've built all five without a framework, framework source code reads as "familiar patterns," not "magic." That's the actual signal you've arrived — not years of experience, not a framework's certificate, but the point where you stop being surprised by what Node.js does.