Module 3: Node.js — JavaScript Beyond the Browser
Module 3 is a broad, high-level tour of the JavaScript ecosystem — everywhere the language shows up outside a plain webpage. Each chapter introduces real tools with real code, at a conceptual depth meant to orient you, not replace a dedicated course on any one of them.
What is Node.js?
JavaScript is a language (Module 1). The browser is one environment it can run in (Module 2). Node.js is a different environment — it runs the exact same JavaScript language, but outside any browser, directly on a computer or server. Node.js is built on Chrome's V8 engine (the same engine covered in Module 1's "How JS Executes"), embedded into a standalone program.
JavaScript (the language)
↓
├── Browser → DOM, fetch, localStorage (Module 2)
└── Node.js → file system, HTTP servers, OS access, process control
Because there's no browser, Node has no document or window — but it adds
abilities a browser deliberately blocks, like reading/writing files on disk directly.
npm, pnpm, Yarn & Bun
npm is not Node.js — it's a separate tool, bundled with Node, for installing and managing packages (reusable code other people published):
npm install express // installs a package into node_modules/
npm install -D typescript // installs as a dev-only dependency
npm run build // runs a script defined in package.json
npx create-react-app my-app // runs a package without permanently installing it
package.json describes a project: its name, dependencies, and scripts. Every installed
package lands in a node_modules folder, and the exact installed versions are locked
in a lockfile (package-lock.json for npm).
pnpm, Yarn, and Bun are alternative package
managers solving the same problem, faster or with different tradeoffs — pnpm saves disk space by
sharing packages across projects, Bun is also a full alternative JavaScript runtime (competing
with Node itself, not just its package manager). All four ultimately read/write a
package.json the same way.
Core Modules (fs, path, os, process, events, streams)
// fs — file system access, not available in the browser
const fs = require("fs"); // or: import fs from "fs"; with ES Modules
fs.readFile("data.txt", "utf8", (err, data) => console.log(data));
fs.writeFileSync("output.txt", "Hello!");
// path — safely build file paths across operating systems
const path = require("path");
path.join("folder", "file.txt"); // "folder/file.txt" (or "folder\file.txt" on Windows)
// os — information about the machine Node is running on
const os = require("os");
os.platform(); // "linux", "darwin", "win32"
os.cpus().length;
// process — the currently running Node program
process.env.NODE_ENV; // read environment variables
process.argv; // command-line arguments
process.exit(1); // stop the program
// events — Node's core pattern for custom events, similar in spirit to DOM events
const EventEmitter = require("events");
let emitter = new EventEmitter();
emitter.on("greet", (name) => console.log("Hello,", name));
emitter.emit("greet", "Chiru");
// streams — process data in chunks instead of loading it all into memory at once
fs.createReadStream("bigfile.txt").pipe(fs.createWriteStream("copy.txt"));
Building an HTTP Server
Node's built-in http module can start a web server with no external framework at all —
this is the raw foundation that Express and other frameworks (next chapter) build on top of:
const http = require("http");
const server = http.createServer((req, res) => {
res.writeHead(200, { "Content-Type": "text/plain" });
res.end("Hello from Node.js!");
});
server.listen(3000, () => console.log("Server running on port 3000"));
CLI Applications
Node is also commonly used to build command-line tools — scripts run directly from a terminal rather than through a browser:
#!/usr/bin/env node
// greet.js
const name = process.argv[2] || "friend";
console.log(`Hello, ${name}!`);
// Run it: node greet.js Chiru → "Hello, Chiru!"
Popular tools like the Vite and Create React App scaffolding commands, ESLint, and Prettier (Module 3's Tooling chapter) are themselves Node.js CLI applications.