Learn Node.js

JavaScript runtime for servers, CLIs and tooling, built on V8 and libuv

30 lessons · 7 hours · 4 levels · covers Node.js 22 LTS

Node.js runs JavaScript outside the browser, pairing Google's V8 engine with an event loop and non-blocking I/O. It powers web servers and APIs, command-line tools, build systems and real-time services, and its npm ecosystem is the largest package registry in the world. Learning Node lets you use one language across the whole web stack.

Before you start

Node.js builds on these; the tree links to the exact lessons you need.

How deep do you want to go?

1. EssentialsRead and write simple code, do the everyday basics10 lessons · 2 hours in total
2. PracticalUse it productively at work, with the usual idioms19 lessons · 4 hours in total
3. AdvancedThe less common features, performance and trade-offs25 lessons · 5 hours in total
4. ExpertInternals and the edge cases experts know30 lessons · 7 hours in total

The Node.js tree

Node.jsWhat Node.js isWhat Node.js isRunning scripts, the REPL and --watchRunning scripts, theREPL and --watchModules: ES modules vs CommonJSModules: ES modulesvs CommonJSnpm and package.jsonnpm andpackage.jsonVersions, lockfiles and npm ciVersions, lockfilesand npm ciReading and writing files with fsReading and writingfiles with fsPaths, URLs and the os modulePaths, URLs and theos moduleThe process object and exit codesThe process objectand exit codesEnvironment variables and .env filesEnvironmentvariables and .env f…Command-line arguments and user inputCommand-linearguments and use…Async patterns in NodeAsync patterns inNodeEvents and EventEmitterEvents andEventEmitterStreams: reading and writing in chunksStreams: reading andwriting in chunksBuilding an HTTP server with node:httpBuilding an HTTPserver with node:httpMaking HTTP requests with fetchMaking HTTPrequests with fetchError handling in Node applicationsError handling inNode applicationsDebugging Node with the inspectorDebugging Node withthe inspectorTesting with node:testTesting withnode:testOffloading CPU work to worker threadsOffloading CPU workto worker threadsModules: import and exportModules: import andexportasync and awaitasync and awaitCallbacks and timersCallbacks and timersPromisesPromisesMaking HTTP requests with fetchMaking HTTPrequests with fetchError handlingError handlingThe event loop and microtasksThe event loop andmicrotasksGarbage collection and memory leaksGarbage collectionand memory leaks
Essentials and Practical shown (19 of 30 lessons); the full list is below. Click a lesson to read it.

All 30 lessons, in order

Getting started

  1. What Node.js is · Essentials · 6 min

    Node.js runs JavaScript outside the browser on V8, with an event loop and built-in modules for files, network and processes.

  2. Running scripts, the REPL and --watch · Essentials · 8 min

    Run files with node, experiment in the REPL, evaluate one-liners and restart automatically on save with --watch.

Modules and packages

  1. Modules: ES modules vs CommonJS · Essentials · 14 min

    Node supports ES modules (import/export) and the older CommonJS (require). Learn how Node picks one and how they interoperate.

  2. npm and package.json · Essentials · 12 min

    Create a project with npm init, install packages, and understand what package.json records and what node_modules is.

  3. Versions, lockfiles and npm ci · Essentials · 10 min

    Read semver ranges like ^1.4.2, understand package-lock.json, and install reproducibly with npm ci.

Files, paths and the process

  1. Reading and writing files with fs · Essentials · 12 min

    Use node:fs/promises to read, write, list and inspect files and directories with async/await.

  2. Paths, URLs and the os module · Essentials · 9 min

    Build file paths portably with node:path, convert file URLs, and query the machine with node:os.

  3. The process object and exit codes · Essentials · 10 min

    Use the global process object for arguments, stdio, the working directory, exit codes and signals.

  4. Environment variables and .env files · Essentials · 9 min

    Read configuration from process.env, load .env files with --env-file, and validate config at startup.

  5. Command-line arguments and user input · Essentials · 11 min

    Parse flags with util.parseArgs, read lines interactively with readline/promises, and accept piped stdin.

Async I/O, events and streams

  1. Async patterns in Node · Practical · 14 min

    From error-first callbacks to promises: promisify old APIs, run work concurrently, add timeouts and cancel with AbortSignal.

  2. Events and EventEmitter · Practical · 11 min

    Emit and listen to named events with EventEmitter, the pattern behind streams, servers and sockets.

  3. Streams: reading and writing in chunks · Practical · 14 min

    Process data piece by piece with readable, writable and transform streams, and connect them safely with pipeline().

  4. Backpressure and custom streams · Advanced · 16 min

    Understand highWaterMark, write() returning false and 'drain', and build Transform streams that respect backpressure.

  5. The event loop phases and libuv · Advanced · 18 min

    Learn the event loop's phases, where nextTick, promises, setImmediate and timers run, and what libuv's thread pool does.

HTTP and networking

  1. Building an HTTP server with node:http · Practical · 14 min

    Create a web server with node:http: route requests, read bodies, set status and headers, and send responses.

  2. Making HTTP requests with fetch · Practical · 10 min

    Call APIs with the built-in fetch: check status, send JSON, set timeouts, stream responses, and reuse connections.

Errors, debugging, testing and security

  1. Error handling in Node applications · Practical · 13 min

    Distinguish operational from programmer errors, use error codes and causes, and handle uncaught exceptions and rejections.

  2. Debugging Node with the inspector · Practical · 11 min

    Debug with --inspect and Chrome DevTools or VS Code: breakpoints, stepping, watching variables, and debugging tests.

  3. Testing with node:test · Practical · 14 min

    Write and run tests with Node's built-in test runner and assert module, including mocks, async tests and coverage.

  4. Security essentials for Node apps · Advanced · 15 min

    Harden Node services: dependency hygiene, input validation, injection and path traversal, secrets, and the permission model.

Concurrency and process lifecycle

  1. Offloading CPU work to worker threads · Practical · 13 min

    Run CPU-heavy JavaScript on worker_threads so the main event loop stays responsive, passing data by message.

  2. Worker pools, shared memory and cluster · Advanced · 16 min

    Scale across cores: pool worker threads, share memory with SharedArrayBuffer, and fork HTTP servers with cluster.

  3. Running other programs: child_process · Advanced · 14 min

    Run external commands with execFile, spawn and fork; stream their output, pass input, and avoid shell injection.

  4. Graceful shutdown and production lifecycle · Expert · 18 min

    Shut down without dropping requests: handle signals, drain keep-alive connections, close resources in order, and add health checks.

Performance and internals

  1. Profiling CPU and event-loop performance · Advanced · 16 min

    Find bottlenecks with --cpu-prof, DevTools and flame graphs, measure with perf_hooks, and watch event-loop delay.

  2. V8 memory, leaks and heap snapshots · Expert · 20 min

    Understand V8's heap spaces and GC, size the heap for containers, and find memory leaks with heap snapshots.

  3. Native addons and Node-API · Expert · 18 min

    How C/C++ and Rust code plugs into Node through Node-API, how addons are built and shipped, and when to avoid them.

  4. AsyncLocalStorage and async context · Expert · 16 min

    Carry request-scoped context such as request IDs through async calls with AsyncLocalStorage, and know what async_hooks underlies it.

  5. diagnostics_channel and tracing · Expert · 15 min

    Publish and subscribe to named diagnostic events with diagnostics_channel and TracingChannel, the hooks APM tools use.