Hello World server
Build a real web server in 10 lines of code
⏱ Est. ~8 min
01 · Read
Time to build something real — a web server in 10 lines of code.
Every website you visit works because there's a server listening for requests and sending responses. When you type a URL in your browser, the browser sends a request to a server, and the server sends back the web page.
That's exactly what you're about to build. It'll run on your own computer, and you'll visit it with your browser. Same technology that powers Netflix, Twitter, and millions of other web apps.
Key points
- Servers listen for requests and send responses
- Express makes building a server easy
- Your server will run locally at http://localhost:3000
02 · Real-machine exercise
Use a text editor to create a file called app.js, saved in your my-server folder (the same working directory where you installed Express). You can copy the entire block below — it's a complete Express web server.
const express = require('express');
const app = express();
const port = 3000;
app.get('/', (req, res) => {
res.send('Hello, World! This is my first server.');
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});03 · Real-machine exercise
Start your server! Run the file with Node. You should see a message confirming the server is running.
node app.js
04 · Quiz
What does the listen function do in an Express server?
- Sends a response to the browser
- Reads files from disk
- Connects to a database
- Starts the server and waits for incoming requests on a port
05 · Fill in the blank
In Express, app.listen(3000) tells the server to listen on _____ 3000.
06 · Real-machine exercise
Open your browser and go to http://localhost:3000. You should see your message on the page! After enjoying your work, return to the terminal and press Ctrl+C to stop the server.
07 · Quiz
If you removed the app.listen(3000, ...) line from your server code and ran it, what would happen?
- The file would run and immediately end — no server would start
- The server would listen on a random port
- Express would automatically pick port 80
- You'd get a syntax error because listen is required
Other lessons in this chapter
⚠ The full interactive experience needs JavaScript. Please enable it and reload.
※ This is an independent Traditional Chinese teaching project — not an official Anthropic product. Claude™ is a trademark of Anthropic, PBC.