Loading video player…

Your First Server With node:http (Overview)

Every API you’ve called has a server deciding its answers. Until now, you’ve been the client. In this first course of the Node Servers and REST APIs path, you write the server.

You’ll build it for Mrs. Okafor, the secretary of Hollybank Allotments, a community garden whose plots people rent. Her phone rings every week with the same three questions: which plots are free, how big plot 7 is, and how to join the waiting list. Each question becomes a request that your server answers, so people can ask the board, a small API, instead of her phone. Here’s a first taste of the finished plot board answering two of them:

Language: Shell
$ curl -i http://localhost:3000/plots/7
HTTP/1.1 200 OK

{"number":7,"size":500,"holder":"Daniel Price"}

$ curl -i http://localhost:3000/plots/99
HTTP/1.1 404 Not Found

{"error":{"code":"plot_not_found","message":"There's no plot 99.","details":null}}

The headers are left out here. Plot 7 gets a 200 and the plot’s details, and plot 99 gets a 404 that the board chooses.

What You’ll Learn

By the end of this course, you’ll be able to write a server with Node’s node:http module that routes requests by method and path, reads JSON bodies, and answers every request with the right status code and a JSON body.

You’ll get there in four steps:

  1. A Server That Answers: answer requests.
  2. Routing Requests: route them by method and path.
  3. Reading Request Bodies: read the bodies they send.
  4. Project: The Hollybank Plot Board: build the board from Mrs. Okafor’s brief, and explain it to the AI mentor that’s built into RealJS.

Before You Start

You should be comfortable with:

You need a current Node LTS (this course uses Node 26), a terminal, and any editor.

How the Course Works

The course has text lessons and short videos, a coding exercise after each section, a project, and a quiz. Follow the lessons on your own computer with the course’s code download. The exercises run in your browser, so there’s nothing to install.

The course has one code download, a ZIP file below this video. Two of its folders get you started:

  • 01-call-server/: the finished plot board, to try out first. You’ll start it with npm start and send requests to it in the next lesson.
  • 02-start-server/starting-project/: the starting project, with package.json, tsconfig.json, and plots.json, which you’ll build your own board in.

The other folders hold the board as each lesson leaves it.

Next, in Call a Server You Didn’t Write, you’ll try the finished board.

Download

Course Slides (.pdf)

878.4 KB
Download

Sample Code (.zip)

43.5 KB

00:00 Welcome to Your First Server With node:http! Every API you’ve called has a server deciding its answers. Until now, you’ve been the client. In this first course of the Node Servers and REST APIs path, you write the server.

00:18 This is Hollybank Allotments’ plot board, a small API for a community garden of rented plots. Ask about plot 7, and it sends a 200 with the plot’s details.

00:29 Ask about plot 99, and it chooses a 404.

00:34 It’s for Mrs. Okafor, the garden’s secretary, whose phone rings weekly with the same three questions. Which plots are free? How big is plot 7? How do I join the waiting list?

00:47 Each question becomes a request your server answers, so people ask the board, not her phone.

00:55 By the end, you’ll be able to write a server with Node’s node:http module that routes requests by method and path, reads JSON bodies, and answers every request with the right status code and a JSON body.

01:09 You’ll answer requests, route them, and read their bodies. Then you’ll build her board and explain it to the built-in AI mentor.

01:20 You should be comfortable calling APIs and writing strict TypeScript. You need a current Node LTS, Node 26 here, a terminal, and any editor.

01:32 Expect text lessons, short videos, an exercise after each section, a project, and a quiz. Follow the lessons on your computer. The exercises run in your browser, so there’s nothing to install.

01:46 Below is one code download: the finished board, to try first, and the starting project, to build in. Next, in Call a Server You Didn’t Write, you’ll try the finished board.

Become a Member to join the conversation.