Skip to main content

Introduction to Node.js

Understand what Node.js is, how it works, and build your first HTTP server.

Asynchronous Work

Master the event loop, callbacks, promises, streams, and non-blocking I/O.

Command Line

Run scripts, use the REPL, read environment variables, and handle I/O.

File System

Read, write, and manage files and directories with Node.js built-ins.

HTTP & Networking

Work with HTTP transactions, the Fetch API, WebSockets, and proxies.

Package Management

Use npm, publish packages, and understand ABI stability for native modules.

Diagnostics

Debug, profile, analyze memory, and generate flame graphs.

Security

Apply Node.js security best practices to protect your applications.

Testing

Write tests, mock dependencies, and collect code coverage with the built-in test runner.

TypeScript

Run TypeScript with Node.js — natively, via transpilation, or with ts-node.

What is Node.js?

Node.js is an open-source, cross-platform JavaScript runtime built on the V8 engine that powers Google Chrome. It executes JavaScript outside the browser, enabling server-side development with the same language you use on the frontend. Node.js uses a non-blocking, event-driven architecture that handles thousands of concurrent connections in a single process — without the complexity of thread management.
server.js
import { createServer } from 'node:http';

const hostname = '127.0.0.1';
const port = 3000;

const server = createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});
1

Install Node.js

Download and install Node.js from nodejs.org.
2

Create a script

Save the code above as server.js.
3

Run it

node server.js
4

Open in your browser

Visit http://127.0.0.1:3000 to see Hello World.

Learning path

New to Node.js? Work through the guides in order:
  1. Introduction to Node.js — understand the runtime and its unique advantages
  2. How much JavaScript do you need? — assess your prerequisite knowledge
  3. Differences from the browser — key distinctions for browser developers
  4. Asynchronous flow control — the core of effective Node.js programming
  5. Don’t block the event loop — the most critical rule in Node.js
These guides are sourced from the Node.js community and reflect current best practices. They cover Node.js LTS releases.

Build docs developers (and LLMs) love