1. Concept library
  2. Backend with Node.js
  3. Module 2: HTTP fundamentals

Concept

Requests and responses

An HTTP request has a method, a path, headers and sometimes a body; the response has a status, headers and a body. Everything a web framework does is a convenience around reading one and writing the other.

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Name the parts of an HTTP request and a response
  2. Write a handler with the http module that reads the request and writes a response
  3. Spot the code path that never ends the response

In practice

A few lines that show Requests and responses doing its job.

JavaScript
import { createServer } from "node:http";

createServer((req, res) => {
  if (req.method === "GET" && req.url === "/health") {
    res.writeHead(200, { "content-type": "application/json" });
    res.end(JSON.stringify({ ok: true }));
    return;
  }
  res.writeHead(404).end();
}).listen(3000);

The common mistake

Watch for

Forgetting to end the response on some code path. The client waits until it times out, and the connection is held open; every branch must send a response.

What to know first

Your roadmap puts these before Requests and responses, unless you already know them.

How it stays learned

Once a session shows you understand Requests and responses, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled

Where it leads

Topics that build on Requests and responses.

Next in the moduleStatus codes →