Level 1 · Complete beginner · 10 min
What a Server Actually Does
Learn what a server is: a program that waits for requests and sends back responses.
What you will learn
- Define what a server is in plain terms
- Explain the client-server relationship
- Describe the listen-receive-respond loop a server runs
- Distinguish a server process from a website
The idea
A server is just a program that stays running and waits. When a message (a request) arrives, it figures out what is being asked, does some work, and sends a message back (a response). That is the entire job, repeated forever.
Why does this matter?
Every app you use with an internet connection -- a to-do list, a bank app, a game leaderboard -- relies on a server somewhere holding the real data and rules. The browser or mobile app is just the front door; the server is the building behind it.
A real-world analogy
Think of a restaurant kitchen. The dining room (client) sends orders (requests) to the kitchen (server). The kitchen prepares the dish (processes the request) and sends the plate back out (the response). The kitchen does not go looking for customers -- it waits for orders to come in.
See it in code
const http = require("http");
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader("Content-Type", "text/plain");
res.end("Hello from the server!");
});
server.listen(3000, () => {
console.log("Server listening on port 3000");
});Line by line
http.createServer((req, res) => {...})Creates a server object and gives it a function that runs EVERY time a request arrives -- req is the incoming request, res is how you send a reply.
res.statusCode = 200;Sets the outcome code -- 200 means "this worked fine".
res.end("Hello from the server!");Sends the response body back to whoever asked, and finishes the reply.
server.listen(3000, ...)Tells the server to start waiting for requests on port 3000 -- nothing happens until this is called.
What do you think happens?
If no request ever arrives, what does the callback function passed to http.createServer do?
Have a guess before you read on. Guessing wrong is part of learning it.
Try it yourself
Imagine three requests arrive one after another for a running server. In what order does the server handle them, and does the server ever run more than one at the exact same instant per request handler?
Worth knowing
Common mistake: confusing "a server" with "a website" or "a computer". A server is software -- a running process -- that can live on your laptop, a data center, or the cloud. The physical machine is sometimes also called a server, but the important thing here is the always-listening program.
The proper words for it
- Server
- A program that listens for incoming requests and sends back responses.
- Client
- Whatever sends the request -- a browser, a mobile app, another server.
- Request
- A message asking the server to do something or fetch something.
- Response
- The message the server sends back with a result.
- Port
- A numbered "door" on a machine that a server listens on for connections.
Where you'll meet this
When you open a weather app, it sends a request to a weather server, which looks up data and responds with today's forecast as a message. The same request-response loop powers social feeds, online banking, and multiplayer games.
Lesson recap
- A server is a long-running program that waits for requests
- Clients send requests; servers send responses
- The core loop is: listen, receive, process, respond, repeat
- A server is software, not just a physical machine
Still fuzzy on any of this?
That's normal, and it's not a dead end. Pick a different way to hear it.
Quick check
1. What is the core job of a server?
2. In the client-server relationship, who initiates the request?
3. What does server.listen(3000, ...) do?