Node.js Foundations in Node.js

Node.js Foundations is the first chapter of the free Node.js tutorial. It starts with what Node.js is and ends with you sharing code between files and installing packages with npm.

What each lesson covers:

  • Introduction to Node.js: What Node.js is and why it was made, its history, V8, libuv and C++ bindings, Node.js versus browser JavaScript, Deno and Bun, LTS versus Current, installing Node.js and version managers, running scripts, the REPL, common CLI flags, and the global object, console and built-in globals.
  • Modules in Node.js: What a module is, module scope, CommonJS with require and module.exports, the module wrapper, how Node.js finds modules, caching and circular imports, JSON files, ES modules with import and export, import.meta, dynamic import and top-level await, using CommonJS and ES modules together, and running TypeScript files.
  • Packages and npm: What npm and the npm registry are, package.json fields, dependency types, installing and updating packages, semantic versioning and version ranges, package-lock.json and npm ci, npm scripts and node --run, npx and local binaries, how Vite and the Angular CLI use Node.js, npm audit, package entry points with exports and imports, and optional workspaces, publishing and other package managers.

Every lab runs a small Node.js runtime in your browser, in JavaScript or TypeScript (pick one in the Language menu at the top). Examples that need the real operating system show output from real Node.js.

Lessons in this section

  1. Introduction to Node.js

    What Node.js is and why it was made, its history, V8, libuv and C++ bindings, Node.js versus browser JavaScript, Deno and Bun, LTS versus Current, installing Node.js and version managers, running scripts, the REPL, common CLI flags, and the global object, console and built-in globals.

    • Explain what Node.js is and why it is non-blocking
    • Name the jobs of V8, libuv and the C++ bindings
    • Tell browser JavaScript and Node.js apart
    • Install Node.js and run a script with arguments
  2. Modules in Node.js

    What a module is, module scope, CommonJS with require and module.exports, the module wrapper, how Node.js finds modules, caching and circular imports, JSON files, ES modules with import and export, import.meta, dynamic import and top-level await, using CommonJS and ES modules together, and running TypeScript files.

    • Split a program into modules and share code with exports
    • Use CommonJS require and module.exports correctly
    • Explain how Node.js finds a module and caches it
    • Use ES modules with import, export and import.meta
  3. Packages and npm

    What npm and the npm registry are, package.json fields, dependency types, installing and updating packages, semantic versioning and version ranges, package-lock.json and npm ci, npm scripts and node --run, npx and local binaries, how Vite and the Angular CLI use Node.js, npm audit, package entry points with exports and imports, and optional workspaces, publishing and other package managers.

    • Read and edit package.json
    • Choose the right dependency type and version range
    • Explain package-lock.json and when to use npm ci
    • Write npm scripts and pass arguments to them