Chapters
Narrated with a synthetic Indian English voice from a script written by the instructor. Code, browser and terminal output come from the tested lesson files.
In this lesson you will
- Name the parts of a URL
- Describe the request and response cycle
- Read HTTP status codes like 200 and 404
- Run a tiny web server on your own computer
Every website you have ever used works the same way. A browser asks a computer somewhere for a file, that computer answers, and the browser draws what it received. Once you can picture that conversation, HTML, CSS and JavaScript stop being magic: they are simply the files being sent back.
The parts of a URL
Take the address https://example.com/menu?day=monday. Each part tells the browser something different.
- https://
- The scheme: the rules for the conversation. HTTPS is HTTP sent over an encrypted connection.
- example.com
- The domain name. DNS, the internet's phone book, turns it into the IP address of the server.
- /menu
- The path: which page or file on that server you want.
- ?day=monday
- The query string: extra information sent with the request.
Request and response
- 1You enter a URLThe browser looks up the domain's IP address through DNS.
- 2The browser sends a requestIt connects to the server and sends a request such as GET /menu, plus headers describing itself.
- 3The server respondsIt sends back a status code, headers like Content-Type, and the body: usually HTML.
- 4The browser rendersIt reads the HTML, asks for any CSS, JavaScript and images it mentions, and paints the page.
A single page usually needs many requests: one for the HTML, then one for each stylesheet, script and image. Open Chrome DevTools (F12), choose the Network tab and reload any page to watch them happen.
Status codes
Every response starts with a three-digit status code. You will meet these constantly:
- 200 OK: here is what you asked for.
- 301 Moved Permanently: the page lives at a new address, which the response gives.
- 404 Not Found: the server has nothing at that path.
- 500 Internal Server Error: the server hit a problem while answering.
Build your own server
The quickest way to understand a server is to write one. Install Node.js (the LTS version from nodejs.org), create a folder, and save this as server.mjs. It uses only what ships with Node, so there is nothing else to install.
// server.mjs — a tiny web server using only Node's built-in http module.
// Run it with: node server.mjs then open http://localhost:3000
import { createServer } from "node:http";
const PORT = 3000;
const server = createServer((request, response) => {
// Every request the browser makes shows up here.
console.log(`${request.method} ${request.url}`);
if (request.url === "/") {
response.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
response.end("<h1>Hello from my first server</h1><p>The browser asked, the server answered.</p>");
return;
}
// Anything else: tell the browser we don't have it.
response.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" });
response.end("404 Not Found");
});
server.listen(PORT, () => {
console.log(`Listening on http://localhost:${PORT}`);
});In VS Code, open the terminal (Ctrl + `) in that folder and start it:
node server.mjs
Listening on http://localhost:3000Open http://localhost:3000 in your browser and you will see the heading. Look back at the terminal: the server printed GET /, the request your browser just made. You will probably also see GET /favicon.ico: browsers ask every site for a small icon automatically, and our server answers that with a 404. Now try http://localhost:3000/anything and you get the 404 response.
You can also make the request without a browser. curl comes with Windows 10 (version 1803 or later), Windows 11, macOS and Linux. Open a second terminal and ask for the full response with -i:
curl -i http://localhost:3000/
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Date: Wed, 11 Nov 2026 22:48:40 GMT
Connection: keep-alive
Keep-Alive: timeout=5
Transfer-Encoding: chunked
<h1>Hello from my first server</h1><p>The browser asked, the server answered.</p>Stop the server with Ctrl + C. Every website, from a bakery's homepage to a large online shop, is this same loop at a bigger scale: a request comes in, the server decides what to send, and the browser renders it.
Add a second page
- Add an if block for request.url === "/about" that responds with 200 and an <h1>About</h1>.
- Restart the server (Ctrl + C, then node server.mjs) and open http://localhost:3000/about.
- Open DevTools > Network, reload, and check the status code and Content-Type of the request.
