Node.js#
Node.js is a JavaScript runtime built on Chrome’s V8 engine that executes JavaScript outside the browser — in your terminal, on servers, and on developer machines. It is the foundation layer the entire modern frontend toolchain depends on.
The Core Idea#
Browsers can execute JS, but they sandbox it — the JS runs on your machine but cannot touch the OS. In 2009, Ryan Dahl asked: what if we took V8 out of the browser and gave it full OS access?
That’s Node. Same V8 engine, same language, but now running like Python would in your terminal. It can read files, open ports, manage processes, access environment variables. No browser. No sandbox. No restrictions.
# This is Node executing JS locally — no browser involved
node app.js
Runtime vs Browser#
A runtime is the environment that executes your code. Every language needs one — Python has CPython, Java has the JVM. For JS:
In the browser — V8 runs inside Chrome/Firefox/Safari, sandboxed, with access only to browser-approved APIs (DOM, fetch, localStorage)
In Node — V8 runs in your terminal with full OS access (filesystem, network sockets, environment variables)
The JS language is the same. What changes is what APIs are available around the engine.
Note
fs.readFile() exists in Node. It does not exist in the browser. If you
accidentally import a Node-only module into browser-bound code, Vite will fail
the build immediately rather than ship broken code.
Two Consequences of Node’s Existence#
1. JavaScript on the server. You can now write backend services in JS — same language on both client and server. This was a significant shift for teams already writing JS.
2. The entire modern frontend toolchain. This is the more relevant consequence.
Every tool you use to build a frontend app — Vite, the TypeScript compiler, ESLint,
npm — is a Node program running on your machine. When you run vite build, Node
is reading your source files, transforming them, bundling them, and writing output
to disk. None of that involves a browser.
Node is the infrastructure layer underneath everything. Before you can run Vite, before you can install React, you need Node — because all those tools are written in JS and need a runtime to execute.
Installation and Version Management#
Node versions matter because tools declare minimum engine requirements. Do not install Node directly from nodejs.org — use a version manager so you can switch versions per project without conflicts.
Recommended options:
nvm — the classic, widely supported
fnm — faster, written in Rust
Volta — pins versions per project automatically
# nvm example
nvm install 20
nvm use 20
node --version
The Local Dev Server#
When you run npm run dev, Node doesn’t just open a file — it starts a real HTTP
server on your machine (typically localhost:5173 with Vite). Your browser connects
to it exactly as it would connect to a remote server. The browser has no idea the
server is local.
That local server handles file watching, hot module replacement, TypeScript transformation on the fly, and serving assets over proper HTTP (required for ES module imports to work correctly).