Node Intro
Node.js runs JavaScript outside the browser using V8 + libuv. Single-threaded event loop, non-blocking I/O, and a huge standard library.
Node.js — what it is
EXAMPLE
// ===== The model =====
// - V8: Google's JS engine
// - libuv: cross-platform async I/O (epoll/kqueue/IOCP)
// - Single thread runs JS; I/O happens on a thread pool
// - Event loop pulls callbacks/promises off queues and runs them
// ===== Hello, http =====
import http from 'node:http';
const server = http.createServer((req, res) => {
res.writeHead(200, { 'content-type': 'application/json' });
res.end(JSON.stringify({ ok: true, path: req.url }));
});
server.listen(3000, () => console.log('http://localhost:3000'));
// ===== File I/O =====
import fs from 'node:fs/promises';
const text = await fs.readFile('package.json', 'utf8');
// ===== ESM is the default in 2026 =====
// package.json: { "type": "module" }
// import / export, top-level await — all work natively
// ===== Built-in package categories =====
// http / https / http2 servers + clients
// fs / path / url filesystem + paths
// crypto hashing, signing, randomBytes
// stream backpressure-aware data pipes
// util / process / os runtime + system info
// child_process / worker spawn processes / threads
// test (node:test) built-in test runner
// node --watch / --env-file modern dev ergonomics
// ===== When Node wins =====
// - JSON APIs and small services
// - Real-time (websockets, server-sent events)
// - Glue scripts and CLI tools
// - Edge / serverless platforms
// ===== When Node hurts =====
// - CPU-bound work (use worker_threads or another runtime)
// - Anything needing strict numeric typing without TypeScript
// - Large memory-resident datasets without careful streaming
// ===== Versioning =====
// Use LTS (even-numbered major). Use nvm / volta to pin per-project.
// ===== Patterns to internalise =====
// - Async first: don't block the event loop
// - Stream big data; never read entire files into memory
// - Prefer the standard library before reaching for a package
// - One concern per process; scale horizontally
// ===== Pitfalls =====
// - Synchronous fs calls in request handlers
// - CPU-heavy JSON.parse on huge bodies inside the loop
// - Forgetting to handle 'error' events on streams -> crashes
// - process.env strings vs typed config; validate at boot
Why it matters
Node is the language platform behind most modern API and tooling work. Single-threaded event loop + a deep std lib + npm ecosystem mean you can ship a service in an evening. The discipline is keeping CPU off the loop and streaming what does not fit in memory.
Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.
Example
Example
// Node runs JavaScript outside the browser.
console.log('Running on Node', process.version);
Try it Yourself »
Exercise
Print the Node version.
node
A two-character flag.
Discussion
Loading…