What is Node.js?
Node.js is not a language, not a framework — it's a runtime environment that lets JavaScript run outside the browser.
The Architecture
Node.js is built on two core components that work together:
The Event Loop — Simplified
Node.js runs on a single thread. This sounds like a weakness, but it's actually its superpower — here's why:
Because Node hands I/O work to the OS and continues, a single Node process can handle thousands of simultaneous connections — all waiting for databases, files, or network responses — without spawning thousands of threads.
Node.js vs Other Runtimes
Node.js is great for ✓
Node.js struggles with ✗
Your First Node.js Script
Open a terminal and try this — no framework, no npm packages:
// hello.js
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ message: 'Hello from Node.js!' }));
});
server.listen(3000, () => {
console.log('Server running at http://localhost:3000');
});
# Run it
node hello.js
# In another terminal, test it
curl http://localhost:3000
This is a complete HTTP server in 8 lines. Express (which you'll learn next) just makes this pattern much more comfortable to work with at scale.
Node Version Management
Always use a version manager — never install Node.js directly. The two most popular:
- nvm (Node Version Manager) — the classic, shell-based
- fnm (Fast Node Manager) — newer, faster, Rust-based
# Install a specific version
nvm install 20
# Use it in the current project
nvm use 20
# Pin the version for a project (.nvmrc file)
echo "20" > .nvmrc
🧠 Check Your Understanding
Go Deeper
Primary source: nodejs.org — Introduction to Node.js
Video: Fireship — Node.js Explained in 100 Seconds
Ask your teacher: "What happens when you block the event loop with a big loop?" or "Show me non-blocking vs blocking I/O side by side."