After this lesson, you will be able to: Skim Node.js core: the event loop in Node, core modules (fs, http, stream, crypto), and what makes Node good at I/O.
Full Node.js depth lives in the pl-node sub-track. This lesson gives the overview from the JS-dev perspective.
Ryan Dahl (2009) wanted a non-blocking I/O server. V8 + libuv (async I/O library) + a JS API = Node. Single-threaded event loop runs JS; libuv thread pool handles blocking I/O (file system, DNS). Excellent for I/O-heavy workloads (servers, proxies, build tools). Mediocre for CPU-heavy (use worker_threads or spawn other processes).
Available without npm install.
import { readFile, writeFile } from "node:fs/promises";import path from "node:path";import { createHash, randomBytes } from "node:crypto";import { fileURLToPath } from "node:url";import os from "node:os";// Read a file (async)const data = await readFile("data.json", "utf-8");// Get the directory of the current module (ESM equivalent of __dirname)const __filename = fileURLToPath(import.meta.url);const __dirname = path.dirname(__filename);// Hashconst hash = createHash("sha256").update("hello").digest("hex");// Random bytesconst token = randomBytes(32).toString("hex");// System infoconsole.log(os.platform(), os.cpus().length);
Pipe data without buffering everything in memory.
import { createReadStream, createWriteStream } from "node:fs";import { createGzip } from "node:zlib";import { pipeline } from "node:stream/promises";// Compress a 1GB file without buffering itawait pipeline(createReadStream("huge.txt"),createGzip(),createWriteStream("huge.txt.gz"),);// Streams = HTTP, file I/O, compression, encryption, composable building blocks.
Reading huge files with readFile (loads entire file into memory). Use createReadStream for anything > a few MB. Blocking the event loop with sync APIs (readFileSync, JSON.parse on huge strings). Workers or worker_threads. Skipping `node:` prefix on imports. Modern Node prefers `node:fs` over `fs`. Forgetting that fs.promises is the modern async API; old `fs.readFile(path, callback)` is callback-style.
Pick the practical answer.
Sign in and purchase access to unlock this lesson.