Free through lesson 3

Node.js for Beginners

From setting up your environment through modules, async code, file I/O, HTTP and Express, SQLite, testing and running in production. Fifty lessons that take you to the point where you can assemble a notes API and a CLI yourself and keep them running. Every piece of code and result shown was produced by actually running Node.js v26.7.0.

about 4 hours in total (estimate)

Slides for this course (for classes and in-house training) →

Curriculum

The 50 lessons are grouped into seven chapters. Working through them in order is the best way, but you are welcome to dip into whatever interests you. Note: this cannot run inside the browser, so try it with your own node (version 22 or later).

Chapter 1 — Getting started (lessons 1–5)

You get to grips with how Node.js runs and set up your environment with a version manager. You cover the different console methods, command line arguments, environment variables and .env, so values can come in from outside.

Chapter 2 — Modules and packages (lessons 6–10)

You split code across files and pull in other people's. You pin down the difference between CommonJS and ES Modules along with the rules that decide which is which, then go on to package.json and semantic versioning in npm.

Chapter 3 — Async code (lessons 11–17)

The high point of the course. You feel the problem with synchronous code by actually freezing the process, then work up through callbacks, promises and async/await. The chapter closes with the event loop and error handling.

Chapter 4 — Files and I/O (lessons 18–26)

From building paths through reading and writing files, working with directories and handling JSON. The second half — streams, EventEmitter, Buffer and readline — lets you push large amounts of data through at constant memory.

18

The path module and building paths

The difference between join and resolve, mixing up __dirname and process.cwd(), and validating before joining user input onto a path.

about 5 min 🔒 Basic
19

Reading files

Why fs/promises is the default. That omitting utf8 gives you a Buffer, that you branch on the error code, and that large files go line by line.

about 5 min 🔒 Basic
20

Writing files

writeFile empties the file the instant it opens it. Making writes unbreakable with a temporary file plus rename, and using a stream for large output.

about 4 min 🔒 Basic
21

Working with directories

Make recursive the default for mkdir. Since readdir's recursive cannot exclude node_modules, write your own walk or use fs.glob.

about 5 min 🔒 Basic
22

Reading and writing JSON files

How require('./config.json') gets cached. What stringify loses, the round-trip problem of Date becoming a string, and adding the filename to a SyntaxError.

about 5 min 🔒 Basic
23

Streams

The mechanism that turns 620MB of memory into 69MB. Why you use pipeline rather than pipe, and the standard form for backpressure.

about 5 min 🔒 Basic
24

EventEmitter

How on and emit work. That emit is synchronous, that only 'error' throws when nobody is listening, and forgetting to remove a listener.

about 5 min 🔒 Basic
25

Buffers and character encodings

Moving between bytes and strings. That subarray is not a copy, why text breaks at a chunk boundary, and three ways to fix it.

about 5 min 🔒 Basic
26

Interactive programs with readline

Asking one question at a time with readline/promises. How forgetting rl.close() hangs everything, and supporting both interactive and piped input.

about 4 min 🔒 Basic

Chapter 5 — HTTP and Express (lessons 27–34)

You write the server, the router and body parsing yourself with the raw http module before moving to Express. Knowing exactly what Express is doing for you, you go on to REST APIs and error design.

27

Building a server with the http module

req is a Readable, res is a Writable. The difference between setHeader and writeHead, specifying a charset, and serving files with pipeline.

about 6 min 🔒 Basic
28

Writing your own router

A fifty-line router. Extracting path parameters with URLPattern, distinguishing 404 from 405, and catching exceptions in one place.

about 4 min 🔒 Basic
29

Request bodies and a JSON API

Why there is no req.body. How body += chunk breaks non-ASCII text, and a body reader with a size limit.

about 5 min 🔒 Basic
30

An HTTP client with fetch

fetch does not throw on a 404. That the real cause is in err.cause, that you always add a timeout, and what makes a request worth retrying.

about 6 min 🔒 Basic
31

Getting started with Express

A mapping table against the raw http module. The difference between res.send and res.json, the one line of express.static, and why you place your own 404 handler.

about 5 min 🔒 Basic
32

Express middleware

Forget to call next() and the request just stops. The four levels of scope, and the fact that express.json() does the same job as your own code from lesson 29.

about 6 min 🔒 Basic
33

A REST API in Express

URLs are nouns, actions are methods. What PUT loses that PATCH does not, and designing a single shape for error responses.

about 6 min 🔒 Basic
34

Error handling and status codes

Separating the expected from the unexpected. Designing so no stack trace reaches production, and the problem of a failure mid-stream looking like a success.

about 5 min 🔒 Basic

Chapter 6 — Storing data and keeping it correct (lessons 35–42)

You move storage from a JSON file to SQLite, separate out configuration, and add validation with zod. The second half gathers the tools that keep your code correct: debugging, testing and linting.

35

Using a JSON file as a data store

Moving to storage that survives a restart. The lost update where 200 concurrent increments give you 1, and a ten-line mutex.

about 5 min 🔒 Basic
36

Persisting data with SQLite

node:sqlite is built in, so there is nothing to npm install. Placeholders, converting types at the boundary, and a bulk INSERT made a thousand times faster by a transaction.

about 5 min 🔒 Basic
37

Separating configuration and switching environments

Measuring the precedence of --env-file. Splitting files per environment, confining loading to config.js, and failing at start-up.

about 5 min 🔒 Basic
38

Input validation (zod)

Thirty hand-written lines become twelve. safeParse and .strict(), converting query strings with z.coerce, and localized messages in one line.

about 6 min 🔒 Basic
39

How to debug

console.log gives up at depth two. util.inspect and debuglog, reading a stack trace, and the --trace-* flags.

about 5 min 🔒 Basic
40

Writing tests with node:test

Tests run with zero config files and zero dependencies. When to use assert/strict, and how to read the diff on a failure.

about 5 min 🔒 Basic
41

Async tests and mocking

Solving it in the design, through dependency injection. mock.fn and mock.method, retry tests with zero waiting, and testing HTTP with listen(0) and fetch.

about 5 min 🔒 Basic
42

ESLint and Prettier

ESLint finds bugs; Prettier makes things look consistent. Writing a flat config, and the point that what --fix cannot fix is the part that matters.

about 5 min 🔒 Basic

Chapter 7 — Professional tooling and wrapping up (lessons 43–50)

TypeScript, logging, CLIs, child processes, worker_threads, measurement and graceful shutdown. You finish by assembling a notes API and CLI that pull all of it together.

43

Using TypeScript

node src/main.ts runs as it is. But it does no type checking, so tsc --noEmit takes that half of the job, and syntax that cannot be erased is off limits.

about 5 min 🔒 Basic
44

Logging and handling exceptions in production

Eighty lines of structured logging. Redacting secrets mechanically, serializing an Error, and carrying a request ID around with AsyncLocalStorage.

about 5 min 🔒 Basic
45

Building a CLI tool

The shebang and the bin field. Since parseArgs cannot handle subcommands in one pass, you slice argv yourself. Exit codes and detecting a TTY.

about 5 min 🔒 Basic
46

External commands with child_process

When to use exec, execFile, spawn and fork. How passing user input to exec executes commands, and the 1MB maxBuffer.

about 5 min 🔒 Basic
47

Heavy work with worker_threads

Getting CPU-bound work off the main thread. A worker pool and SharedArrayBuffer, and the fact that none of it helps with I/O.

about 5 min 🔒 Basic
48

Measuring performance

Do not guess, measure. Why one measurement is never enough, and mark/measure, event loop delay and CPU profiles.

about 5 min 🔒 Basic
49

Running in production and graceful shutdown

The five stages between receiving SIGTERM and exiting. How /health and /ready differ, and whether you should write cluster yourself.

about 5 min 🔒 Basic
50

[Project] Wrapping up with a notes API and CLI

Express and zod are the only third-party packages. Integrating the tools from 49 lessons into one app, from configuration and the database through validation, logging and shutdown.

about 4 min 🔒 Basic

Once you have finished all 50 lessons, add types with TypeScript for Beginners, or connect to the frontend with Next.js for Beginners. Membership unlocks every course.