What is a server, in plain words?
A server is a program that waits. It sits on a computer, listens for messages, and answers each one. When your browser opens a page, it sends one of those messages, called a request. The program on the other end reads it, decides what to send back, and replies with a response. Then it goes back to waiting.
Think of the counter at a bakery. Customers walk up one at a time and ask for something: a loaf of rye, today’s opening hours, the price of a croissant. The person behind the counter listens, looks up the answer or fetches the item, and hands it over. A web server does the same job for browsers, thousands of times a minute if the site is busy.
The word server can mean two things, and both are correct. It can mean the program, like the one in server.js, or the computer that runs it. In this course it nearly always means the program, because that is the part you write.
What happens when you open a web page?
Every page visit is a short conversation. Your browser sends a request that says, roughly, “please give me the page at this address”. The server sends back a response with three parts: a status code that says how it went, some headers that describe the answer, and a body that holds the actual content, such as HTML.
The first line of a request names a method and a path. GET / means “get me whatever lives at the top of this site”. GET /hours means “get me the hours page”. The server looks at that pair, finds the code that handles it, and runs it. That handler is the part you control.
Most pages need more than one request. After the HTML arrives, the browser reads it and asks again for each stylesheet, script and image it mentions. A simple page might take five requests. A heavy one might take a hundred. Every single one goes through the same loop: request in, code runs, response out.
- The browser sends a request with a method and a path, like
GET /. - The server finds the route that matches and runs its code.
- That code sends a response: a status, headers and a body.
- The browser shows the body, or asks for more files it mentions.


What does each line of server.js do?
The starting code is a complete server in thirteen lines, comments included. It uses Express, the most widely used way to write web servers in Node.js. Node.js runs JavaScript outside the browser, and Express adds the tools that make answering requests short and readable.
The first two lines load Express and create an app. The app is your server: everything else is instructions you attach to it. app.get('/', ...) says “when a GET request for / arrives, run this function”. The function receives two objects. req describes the request that came in, and res is how you answer it.
res.send('Hello from the bakery server') writes the answer and sends it. Express fills in the details you didn’t mention: the status 200 OK, a Content-Type header saying the body is HTML, and the length of the body. Finally, app.listen(3000, ...) starts the server and keeps it running, waiting for requests on port 3000.
const express = require('express'); // load Express
const app = express(); // create the server app
app.get('/', (req, res) => { // when GET / arrives...
res.send('Hello from the bakery server'); // ...answer with this
});
app.listen(3000); // start waiting for requestsHow does the practice server on this page work?
A real server runs on a computer somewhere and opens a network port. This one runs inside your browser tab, in a separate background worker, so nothing reaches your computer’s network and nothing reaches the internet. When you press Send, the request travels to that worker as a message instead of across a network.
The code you write is real Express code. Copy server.js into a folder on your own computer, install Node.js and Express, run node server.js, and it behaves the same way. The practice server supports the parts of Node.js and Express this course teaches, and it tells you plainly when you use something it doesn’t have.
Two things are deliberately different. The practice server restarts by itself every time you edit the code, which a plain node server.js does not do. And its clock and random numbers are pretend, so the same code and the same requests always give the same answers. That makes Check my work reliable.
What do localhost and port 3000 mean?
localhost is the name every computer uses for itself. When a developer runs a server on their own laptop and opens http://localhost:3000 in a browser, the request never leaves that laptop. It goes out of the browser and straight back in to the server program next door. It is the standard way to try a server before anyone else can see it.
A port is a numbered door on a computer. One computer can run many servers at once, and the port number says which one should get a request. Websites on the public internet use port 443 for HTTPS, so you never type it. During development people pick an unused number, and 3000 is a common choice for Node.js servers.
The request bar above the views shows localhost:3000 for the same reason. If you change the number in app.listen(), the address changes with it.
Why does a server keep running?
Most programs you have written so far run from top to bottom and then stop. A server is different because of one line: app.listen(). It tells Node.js to keep the program alive and hand it every request that arrives on that port, forever, until someone stops it.
That is why the function you pass to app.get() doesn’t run when the file runs. It is stored and saved for later. It runs once for each matching request, possibly millions of times over the life of the server. The code at the top level, such as creating the app and calling app.listen(), runs only once, at startup.
You can see both moments in the Log view. The message “Bakery server is ready” appears once, when the server starts. Each request then adds its own lines, if the route prints anything.
What happens when no route matches?
Press the **GET /hours** button. The server answers with status 404 Not Found and a tiny HTML page that says “Cannot GET /hours”. You didn’t write that page. Express sends it automatically whenever a request arrives and none of your routes match its method and path.
The status code is the important part. 200 means the server found what was asked for. 404 means it understood the request but has nothing at that address. Browsers, search engines and other programs read that number before they read anything else, which is why later lessons spend time getting it right.
The Requests view shows the difference clearly: the GET / exchange says which route handled it, and the GET /hours exchange says no route matched. When a page doesn’t show what you expect, that line is the first thing to read.
Where do real servers run?
While you build, the server runs on your own computer at localhost. To put it on the internet, you run the same code on a computer that is always on and reachable from anywhere, usually rented from a hosting company. People type your domain name, their browser finds that computer, and the request arrives at your app.get() routes just as it does here.
Static websites, like the ones from the HTML and CSS courses, don’t need a program like this at all. A plain file host can send the same files to everyone. You need a server of your own when the answer depends on something: who is asking, what is in a database, what someone just typed into a form. The rest of this course builds exactly those things, one route at a time.
Field notes
- A server is a program that waits for messages and answers each one.
- Each page visit is a request from the browser and a response from the server.
- The line
app.listen()keeps the server running so it can wait for more requests. - When no route matches a request, Express answers with a 404 page.
Easy to get wrong
Writing the text inside the route isn’t enough. The server only answers when your code calls a method on res, such as res.send(). Without it the browser keeps waiting, and the Requests view shows “No reply”.
On your own computer, Node.js reads server.js once, when it starts. Editing the file changes nothing until you restart the server. Running node --watch server.js restarts it whenever you save, which is what the practice server here does for you.
Routes only describe what to do. Without app.listen() the program sets them up and then exits, so there is nothing to receive requests. The Status line here says the server isn’t listening.
Questions people ask
Do I need to know JavaScript before this course?
It helps a lot. Express servers are written in JavaScript, and lessons use functions, objects and arrays without explaining them from scratch. If those words are new, the first part of the JavaScript course covers them.
Is Express the only way to build a server?
No. Node.js has a built-in http module that Express is built on, and there are many other frameworks in Node.js and in other languages, such as Python, PHP and Go. The ideas in this course, routes, requests, responses, status codes and headers, are the same in all of them.
Why does my browser show a different address than localhost?
On a live website the server runs on a computer with a public address and a domain name, so visitors type that name instead. localhost only ever means “this same computer”, which is why it works for testing and can’t be shared with anyone else.
Can the practice server reach the internet or my files?
No. It runs inside this browser tab, receives requests only from the Send and Try buttons and the Browser view, and has no network access. The files and database it uses are small pretend copies that reset when you start over.