For years JavaScript could only live inside a tab. The same developer therefore wrote the interface in one language and the server in another.
Node changed that by lifting the engine out of the browser and installing it on an ordinary machine. A server, a backup script, a command line tool: all of it becomes writable in the same language.
Definition
Node.js is a runtime that executes JavaScript outside the browser. It reuses the engine that powers Chrome, adds access to the file system and the network, and ships npm in the same package.
// info.js
import { readFile } from 'node:fs/promises';
const text = await readFile('./package.json', 'utf8');
const project = JSON.parse(text);
console.log(project.name + " version " + project.version);
// shop version 1.4.0The file runs through node info.js. The node: prefix names a module supplied by the runtime itself, so there is nothing to install.
What Node adds, and what it removes
| Available in Node | Missing from Node |
|---|---|
node:fs, reading and writing files | document and the whole DOM |
node:http, answering requests | window and its shortcuts |
process, arguments and environment variables | localStorage and cookies |
The language itself does not shift an inch: same arrays, same promises, same Event loop. What differs is the library of functions offered around it.
Node also runs the tooling of web development, even when the final result is a static page. Vite, ESLint and the TypeScript compiler are Node programs, which is why it sits on every front-end machine.
ES modules or CommonJS
Node understands both systems. A .js file is read as CommonJS by default, and as a ES module as soon as package.json declares "type": "module". The .cjs and .mjs extensions settle the matter file by file.
An ES module loses __dirname and __filename on the way, replaced by import.meta.url. That is the difference that surprises people most during a conversion.
Frequently asked questions
Which Node version should I install?
An even-numbered one, which comes with long term support. On a machine shared between several projects, a version manager such as nvm avoids conflicts, since each project can state its own requirement in the engines field.
Is Node a good fit for heavy computation?
Less so than other environments, because your code runs on a single thread: one long calculation blocks every request waiting behind it. Node shines on work that spends its time waiting for the network or the disk, and genuinely intensive work moves into a Web Worker or a separate process.
How do I restart a script on every change?
The node --watch info.js option is now enough, with nothing to install. Node also ships a test runner and an environment file reader, tools that used to demand one more dependency. Our Node.js course starts from these foundations to build a real API.