Node.js Introduction
Node.js brings JavaScript to the server. Built on Chrome's V8 engine with a non-blocking, event-driven architecture — it's perfect for APIs, real-time apps, CLI tools, and anything that needs fast I/O.
What is Node.js?
Node.js is a runtime that lets JavaScript run outside the browser, on servers, in command-line tools and in build scripts. It uses Chrome's V8 engine and adds APIs for files (fs), networking (http), processes and more, with a non-blocking, event-driven design that handles many connections efficiently.
// server.js
import { createServer } from "node:http";
createServer((req, res) => {
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify({ ok: true }));
}).listen(3000);
// terminal
node server.jsCore Built-in Modules
fs / fs/promisesFile read, write, delete, watch, stat
pathjoin, resolve, basename, dirname, extname
http / httpsCreate HTTP servers, make requests
eventsEventEmitter — pub/sub in Node.js
streamReadable, Writable, Transform, pipeline
cryptoHash (SHA256), HMAC, random bytes, UUID
oscpus, platform, homedir, totalmem
child_processexec, spawn — run shell commands
worker_threadsTrue parallelism for CPU-intensive tasks
netTCP server/socket (low-level networking)
url / querystringParse and build URLs and query strings
timers/promisessetTimeout/setInterval as Promises
Common Pitfalls
Interactive Demo
Code Editor
<p>Node.js runs on the server, not in this preview. Here is a minimal server:</p>
<pre>// server.js → run with: node server.js
import {
createServer,
} from "node:http";
createServer((req, res) => {
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify({ message: "Hello from Node", path: req.url }));
}).listen(3000, () => console.log("http://localhost:3000"));</pre>
<p>Visiting <code>http://localhost:3000/hi</code> would return:</p>
<pre id="out"></pre>Preview
Node.js Introduction: summary
Key points
- There's no DOM or
windowin Node.js; the global object isglobalThis. - Prefer async APIs (
fs/promises) over sync ones in servers so requests aren't blocked. - Use LTS (even-numbered) versions in production.
- Modern Node has built-in
fetch, a test runner and--watchmode.
Frequently asked questions
›Is Node.js a programming language?
No. It's a runtime environment that executes JavaScript outside the browser.