Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

NO
Node.js & Express
0/13 completed
Beginner
What is Node.js?Modules and npmWorking with filesCallbacks, promises and the event loop
Intermediate
Events and streamsYour first HTTP serverExpress basicsRouting and middlewareConnecting a database
Advanced
Validation and configurationAuthentication with JWTTesting APIs
Pro
Deploying Node apps to production
Tracks / Node.js & Express / Beginner

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").

bash
node --version     # v26.13.1 (or similar)
npm --version      # npm comes with Node

Tip: 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:

Node.js · editable

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 with fetch('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:

bash
$ node
Welcome to Node.js v26.13.1.
Type ".help" for more information.
> 2 ** 10
1024
> 'node'.toUpperCase()
'NODE'
> .exit

The process object

process describes the running program: its arguments, environment variables and how it exits.

Node.js · editable
  • process.argv is the command line: node greet.js Asha gives ['/path/to/node', '/path/to/greet.js', 'Asha'], so your own arguments start at index 2.
  • process.env holds environment variables, the standard way to configure servers (ports, database URLs, secret keys).
  • process.exit(1) stops the program with an exit code. 0 means success; anything else signals an error to the shell or to the tool that started it.
Node.js · editable

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:

Node.js · editable

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:

Node.js · editable

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

  1. Print a greeting that includes process.version.
  2. Use path.join to build the path users/asha/photos/cat.png from four separate strings, then print its extension with path.extname.
  3. Write a program that reads process.env.PORT and prints Server would start on port X, using 3000 when it isn't set.
✎ Check your understanding

1.What is Node.js?

2.Which of these is NOT available in Node.js?

3.Why should you usually install the LTS version?