What is Node.js?
JavaScript was born in the browser. Node.js takes the same language out of the browser and runs it on a computer or a server, where it can read files, talk to databases and answer web requests. It powers the backends of companies like Netflix, PayPal and LinkedIn, and almost every modern web tool (npm, Vite, ESLint, Prettier, TypeScript) is itself a Node.js program.
What Node.js actually is
Node.js is a JavaScript runtime: a program that runs JavaScript files. It's built from two main parts:
| Part | What it does |
|---|---|
| V8 | Google's JavaScript engine (the one inside Chrome). It compiles your JavaScript to fast machine code. |
| libuv | A C library that gives Node an event loop and non-blocking access to files, the network and timers. |
On top of those, Node adds built-in modules that browsers don't have: fs (files), http (web servers), path, crypto, os, process and many more.
| In the browser | In Node.js |
|---|---|
document, window, the DOM |
No DOM: there is no page |
| Can't read your files | fs reads and writes files |
| Runs code from websites, sandboxed | Runs your own programs with full access to the machine |
fetch, console, setTimeout, URL |
The same: fetch, console, setTimeout, URL all work |
So everything you learned in the JavaScript track (variables, functions, objects, arrays, classes, promises) works exactly the same in Node.
Installing Node.js
Download the LTS (Long-Term Support) version from nodejs.org. LTS versions get security fixes for about three years, so they're what companies run in production. At the time of writing, the active LTS is Node.js 26 ("Lithium").
node --version # v26.13.1 (or similar)
npm --version # npm comes with NodeTip: a version manager such as fnm or nvm lets you install several Node versions and switch between projects:
fnm install 26 && fnm use 26.
Your first program
Save this as hello.js and run it with node hello.js. In this track you can simply press ▶ Run:
How the editors work: every example in this track runs in a Node.js 26 simulated in your browser. Files you create live in a folder called
/app, and web servers you start can be called withfetch('http://localhost:3000'), just like on your computer. A few things that need a real machine (starting other programs, raw network sockets) aren't available.
The REPL
Type node on its own to open the REPL (Read-Eval-Print Loop), an interactive prompt that's perfect for experiments:
$ node
Welcome to Node.js v26.13.1.
Type ".help" for more information.
> 2 ** 10
1024
> 'node'.toUpperCase()
'NODE'
> .exitThe process object
process describes the running program: its arguments, environment variables and how it exits.
process.argvis the command line:node greet.js Ashagives['/path/to/node', '/path/to/greet.js', 'Asha'], so your own arguments start at index 2.process.envholds environment variables, the standard way to configure servers (ports, database URLs, secret keys).process.exit(1)stops the program with an exit code.0means success; anything else signals an error to the shell or to the tool that started it.
JavaScript modules in Node
Modern Node programs use ES modules, the same import/export syntax as browsers. Node also understands the older CommonJS style (require), which you'll see in many existing projects:
The node: prefix makes it clear that a module is built into Node, not downloaded from npm. The next lesson covers modules and npm in detail.
Top-level await
In an ES module you can use await directly at the top level, without wrapping code in an async function:
What Node.js is good at
Node uses a single thread with an event loop: instead of waiting while a file is read or a database answers, it starts the operation, keeps working on other things, and comes back when the result is ready. That makes it excellent for:
- Web servers and APIs that handle many requests that mostly wait on databases and other services
- Real-time apps: chat, live dashboards, multiplayer games (with WebSockets)
- Command-line tools and build tools
- Full-stack JavaScript: the same language on the frontend and the backend
It's a poorer fit for heavy number-crunching (video encoding, machine learning training), which blocks that single thread. You'll learn exactly why in the event loop lesson.
Practice
- Print a greeting that includes
process.version. - Use
path.jointo build the pathusers/asha/photos/cat.pngfrom four separate strings, then print its extension withpath.extname. - Write a program that reads
process.env.PORTand printsServer would start on port X, using3000when it isn't set.
1.What is Node.js?
2.Which of these is NOT available in Node.js?
3.Why should you usually install the LTS version?