Explain it simply
Explain it simply
JavaScript was born inside the browser, where an engine called V8 runs it in Chrome. Node.js takes that engine out of the browser and adds what a program on a real computer needs: reading files, accepting network requests and starting other programs.
Think of one engine fitted into two different vehicles. The browser vehicle is built to show web pages. The Node vehicle is built for servers, command-line tools and automation scripts.
Problem → Why → Solution
The problem: browser JavaScript cannot touch your computer
Say you already know some JavaScript. Now you want to rename 300 photos, or build an API for a mobile app. JavaScript in a browser tab is not allowed to read files on your disk or to sit on a port waiting for requests, because any web site could then reach into your computer.
The opposite move fails too: paste your usual browser code into Node and it crashes at once. Node has no page, so it has no document either.
// Written for a browser tab, then run with: node browser-habit.js
const button = document.querySelector("#save");
button.addEventListener("click", () => alert("Saved!"));
// ReferenceError: document is not definedWhy does this happen?
The JavaScript language itself is identical. What differs is the host, the runtime that runs the language and injects extra objects. A browser supplies document, window and alert; Node supplies process, fs and http. This whole course is about the part Node supplies.
Core concept: Node.js is a runtime
Node.js is not a new language, and it is not a framework like Express. It is a runtime: a program that runs JavaScript on your computer. Picture three parts working together: the V8 engine that executes your code, an event loop that hands file and network work to the operating system and calls your code back when it finishes, and a set of built-in modules such as fs, path, http and crypto.
Built-in modules are loaded with the node: prefix, as in import { readFile } from "node:fs/promises". The prefix states plainly that this is a module shipped inside Node, not a package installed from npm. process is different: it is a global object that is always there without an import, and it is where you read the Node version, command-line arguments and environment variables.
This course targets Node.js 22 or a newer LTS (Long-Term Support) release. LTS lines receive bug and security fixes for years, which is why real projects run them; check nodejs.org for the current one.
The course is split into five chapters. Basic takes you from understanding the runtime to running and organising files. Intermediate covers Node's core modules and Express. Advanced covers what production needs: configuration, testing, security and shutdown. Projects builds a REST API step by step, and Exercises combines everything.
| Chapter | Lessons | What you learn |
|---|---|---|
| Basic | 6 | What Node is, setup, a first app, CommonJS modules, ES modules and package.json |
| Intermediate | 9 | fs, path, http, npm, Express (routing, static files), promises and async/await, events and streams |
| Advanced | 6 | Configuration, the test runner, HTTP security, worker threads, logging, graceful shutdown |
| Projects | 5 | A REST API: GET all, GET one, POST, and a User API mini project |
| Exercises | 2 | Combined practice with core modules and an Express CRUD API |
- You write app.js
- node app.js starts the runtime
- V8 executes your code
- Node APIs reach disk and network
- Output appears in the terminal
The language matches the browser; only the APIs around it change.
General pattern: running a file
// file-name.js
console.log(value);
// In a terminal, inside the folder that holds the file:
// node file-name.jsSave the code in a .js file and run node file-name.js from the folder that contains it. Whatever console.log() prints shows up in the terminal, and the process ends by itself once the file is finished and no work is left waiting.
Example: a first script that prints the course map
This script greets you from Node.js, then prints each chapter with its lesson count and a total. Save it as hello.js and run node hello.js. The last line shows that the window object every browser has does not exist in Node.
// hello.js - run it with: node hello.js
const chapters = [
["Basic", 6],
["Intermediate", 9],
["Advanced", 6],
["Projects", 5],
["Exercises", 2],
];
console.log("Hello from Node.js!");
let total = 0;
for (const [name, lessonCount] of chapters) {
console.log(`${name.padEnd(13)}${lessonCount} lessons`);
total += lessonCount;
}
console.log(`${"Total".padEnd(13)}${total} lessons`);
console.log("Running inside a browser?", typeof window !== "undefined");Code breakdown
- Line 2
const chapters = [Each chapter is stored as a small [name, lessonCount] array. This is ordinary JavaScript you could also write in a browser; nothing Node-specific is needed yet.
- Line 10
console.log("Hello from Node.js!");In Node, console.log() writes to the process's standard output (stdout) instead of DevTools, which is why the text appears in your terminal.
- Line 12
for (const [name, lessonCount] of chapters) {for...of visits each chapter, and destructuring splits the small array into name and lessonCount.
- Line 13
name.padEnd(13)padEnd(13) fills each name with spaces up to 13 characters, so the lesson counts line up in one column.
- Line 17
typeof window !== "undefined"typeof is safe on a name that does not exist: it returns "undefined" instead of throwing. Node has no window, so this prints false.
Hello from Node.js!
Basic 6 lessons
Intermediate 9 lessons
Advanced 6 lessons
Projects 5 lessons
Exercises 2 lessons
Total 28 lessons
Running inside a browser? falseBrowser JavaScript and Node.js side by side
| Part | Browser | Node.js |
|---|---|---|
| How you run code | A <script> tag or the DevTools Console | node file.js in a terminal |
| Host objects | window, document, localStorage | process, Buffer, node: modules |
| Files and network | Locked in a sandbox | Full access, as the OS allows |
| Available in both | console, setTimeout, fetch, URL | console, setTimeout, fetch, URL |
Every lesson follows the same order: a plain explanation, a problem, the core concept, a runnable example, a mini challenge and a quiz. Read the problem section before the code, because it explains why the feature exists at all. Type the examples yourself instead of pasting them, then change something and watch how the output changes. All you need is Node.js 22 or newer, a code editor such as VS Code, and a terminal.
In real projects
Where Node.js shows up in real projects
Node's most visible job is the web backend: JSON APIs, built with frameworks such as Express, that a mobile app or a React frontend calls. It is also a good fit for real-time apps like chat and live dashboards, where thousands of connections stay open at once and non-blocking I/O pays off.
Frontend developers who never write a server still use Node every day: npm, Vite, ESLint, Prettier and the TypeScript compiler are all programs that run on Node. Teams also write automation scripts in Node for database backups, report generation and file conversions, and cloud providers offer Node as a runtime for serverless functions such as AWS Lambda. What you learn here pays off whether you end up on the backend or the frontend.
Common mistakes
Common mistakes
1. Running node from the wrong folder
If the terminal is in Desktop and hello.js lives in Documents/node-course, node hello.js fails with "Cannot find module '...hello.js'" (code MODULE_NOT_FOUND). Node looks for the file relative to the terminal's current folder. cd into the folder first, or give the full path.
2. Typing node commands inside the Node REPL
Typing just node opens the REPL, an interactive mode with a > prompt. Typing node hello.js there is read as JavaScript and gives a SyntaxError. Press Ctrl + C twice (or type .exit) to get back to the shell, then run the file.
3. Reaching for browser-only APIs
alert(), document and localStorage come from the browser, so Node throws a ReferenceError for them. Write to the terminal with console.log(), and store data in a file or a database instead.
Mini challenge
Mini challenge: this week's study plan
Write study-plan.js that prints three lessons you plan to study this week with their minutes, and the total time.
- Store each lesson as a { lesson, minutes } object in an array
- Print each lesson with a number in front
- Show the total in minutes and in hours (2 decimals)
- Use process.versions.node to print whether this is Node 22 or newer
// study-plan.js - run it with: node study-plan.js
const plan = [
// TODO: three { lesson: "...", minutes: 0 } objects
];
// TODO: print a heading line
// TODO: loop over plan, print "1. <lesson> (<minutes> min)", add up minutes
// TODO: print "Total: <minutes> min = <hours> h" with 2 decimals
// TODO: read the major version from process.versions.node and print a checkExpected: The output should be (the last line is true on Node 22 or newer): My Node.js plan for this week: 1. What is Node.js? (20 min) 2. Get Started (Setup) (25 min) 3. Your First App (30 min) Total: 75 min = 1.25 h Node.js 22 or newer: true
Show hint
plan.forEach((item, index) => ...) gives you the index, so number lines with index + 1. process.versions.node is a string like "22.20.0": take split(".")[0] and convert it with Number().
Show solution
// study-plan.js - run it with: node study-plan.js
const plan = [
{ lesson: "What is Node.js?", minutes: 20 },
{ lesson: "Get Started (Setup)", minutes: 25 },
{ lesson: "Your First App", minutes: 30 },
];
console.log("My Node.js plan for this week:");
let totalMinutes = 0;
plan.forEach((item, index) => {
console.log(`${index + 1}. ${item.lesson} (${item.minutes} min)`);
totalMinutes += item.minutes;
});
console.log(`Total: ${totalMinutes} min = ${(totalMinutes / 60).toFixed(2)} h`);
const major = Number(process.versions.node.split(".")[0]);
console.log("Node.js 22 or newer:", major >= 22);Quick quiz 1 / 3
Quick quiz 2 / 3
Quick quiz 3 / 3
What to remember
- Node.js is a JavaScript runtime: the V8 engine, an event loop and built-in modules.
- The language matches the browser, but window/document are gone and process, fs and http are added.
- Built-in modules are imported with the node: prefix, and files run with node file.js.
- The course has 28 lessons across Basic, Intermediate, Advanced, Projects and Exercises.
Introduction to Node.js — Node.js