The problem that created Node.js, how V8 works, Node vs browser JavaScript, installing Node, and running your very first program.
Module F-1 — What Is Node.js and Why Does It Exist?
What this module covers: Before you write a single line of Node.js, you need a correct mental model of what it actually is. Not "JavaScript on the server" — that's a description, not a model. This module covers the problem Node.js was built to solve, what the V8 engine does, how Node.js differs from browser JavaScript, and how to get your environment set up correctly. By the end you will have Node installed, your first program running, and a clear picture of when Node.js is the right tool — and when it isn't.
The Problem That Created Node.js
The year is 2008. You are building a web application. Your backend is written in Java, PHP, or Ruby. Every time a user makes a request — for a page, for data, for a file upload — your server creates a new thread to handle it.
A thread is expensive. It costs memory (typically 2–8 MB per thread). The operating system has to context-switch between them. Under heavy load, you spawn hundreds of threads. Most of them are not computing anything — they're just waiting. Waiting for the database to return rows. Waiting for a file to be read from disk. Waiting for an external API to respond.
This is the thread-per-request model, and its fundamental problem is that it conflates concurrency with CPU usage. You need concurrent connections. You don't necessarily need concurrent CPU work. Most web requests spend 80–95% of their time on I/O — waiting for something external — not on computation.
Analogy: A thread-per-request server is a waiter who stands frozen at your table until the kitchen finishes cooking; Node.js is the waiter who drops your order at the kitchen window and immediately goes to take the next table's order, circling back only when the food is actually ready.
Ryan Dahl, a software engineer, noticed this in 2009. He was experimenting with non-blocking I/O in C and Lua when he came across Google's V8 JavaScript engine, which Google had just open-sourced as part of Chrome. V8 was fast — dramatically faster than other JavaScript engines at the time. And JavaScript, by its design in the browser, was already event-driven. You attached callbacks to button clicks. You didn't block waiting for a user to click.
His insight: take V8 out of the browser, add APIs for the file system and networking, and you have a runtime where I/O is inherently non-blocking. You never wait. You register a callback and go handle something else.
He presented Node.js at JSConf EU in November 2009. The demo — a web server in 8 lines of JavaScript — caused immediate excitement. Node.js was not just a new language runtime. It was a different way of thinking about concurrency.
What Node.js Actually Is
Node.js is three things bundled together:
1. V8 — Google's JavaScript engine, written in C++. V8 compiles your JavaScript to machine code and executes it. It is the same engine that runs JavaScript in Chrome and Edge.
2. libuv — A C library that handles asynchronous I/O. It provides the event loop, thread pool, and cross-platform abstractions for networking (TCP, UDP), file system, DNS, and more. libuv is what makes Node.js non-blocking — when you read a file or make a network request, libuv handles the OS-level call and notifies Node.js when it's done.
3. The Node.js standard library — A set of built-in JavaScript modules: fs for files, http for servers, path for paths, crypto for cryptography, and many others. These are the Node.js APIs you call in your code.
When you run node server.js, what actually happens:
- V8 parses and compiles your JavaScript to machine code
- Your code runs on a single thread managed by V8
- When your code calls an I/O operation (read a file, open a socket), it hands the work to libuv
- libuv queues the operation with the operating system
- The event loop continues running — handling other work, timers, callbacks
- When the OS signals the I/O is complete, libuv puts the callback into the event queue
- The event loop picks it up and runs it
This is the core model. One thread. Non-blocking I/O. Event-driven callbacks. We will go much deeper into the event loop mechanics in Phase 3 — but this mental model is all you need for Phase 1 and Phase 2.
Node.js vs Browser JavaScript
JavaScript runs in two environments: the browser and Node.js. The language itself is the same — the same syntax, the same Array, Map, Promise. But the environment around it is completely different.
| Feature | Browser | Node.js |
|---|---|---|
window object | ✅ | ❌ |
document, DOM | ✅ | ❌ |
process object | ❌ | ✅ |
fs (file system) | ❌ | ✅ |
http (TCP server) | ❌ | ✅ |
require() / import | ❌ (import/export only) | ✅ Both (CommonJS + ESM) |
fetch | ✅ | ✅ (Node 18+) |
localStorage | ✅ | ❌ |
setTimeout / setInterval | ✅ | ✅ |
console.log | ✅ | ✅ |
In the browser, JavaScript's job is to manipulate the DOM and respond to user events. The global object is window. APIs exist to talk to the user's screen.
In Node.js, JavaScript's job is to build servers, process files, and communicate over networks. The global object is global (though in modern code you rarely reference it directly). APIs exist to talk to the operating system.
Sign in to keep reading
The rest of this module is free — sign in with Google to unlock it and track your progress.
Sign in & RegisterDiscussion
0Join the discussion