What a server is, how a request becomes an answer, and how to start one with Express.
Hello from the serverTry itA server receives requests and sends responses. app.get(path, (req, res) => ...) answers one address.
Start listeningExerciseapp.listen(port, callback) starts the server. The callback runs once it is ready.
A second pageExerciseOne app.get per route. Express checks the routes in order and the first match answers.
Cannot GET /helloDebug404 means no route matched the address. Paths must match exactly.
Quick checkQuizRequests, responses, routes, ports and status codes: the basics of every backend.
2. Send JSON
Apps don't want web pages from an API, they want data. res.json() sends it, in exactly the format you learned.
Your first APIExerciseres.json(object) sends data as JSON, with the header that says so (application/json).
A list from the serverExerciseKeep the data in a variable and send it with res.json. Later, the variable becomes a database.
Two answers to one questionDebugEvery request gets exactly one response. Send it once.
Quick checkQuizres.json sends data, one response per request, and the data can be any object or list.
3. Routes with parameters
One route for every player: /api/hello/:name, ?search=pizza, and the 404 for things that do not exist.
Hello, anyoneExercise:name in a path is a parameter, and req.params.name holds its value.
A search APIExercisereq.query holds the values after ?. filter keeps the matching items.
Found, or 404Exerciseres.status(code) sets the status. return stops the function so it answers only once.
The game that was always missingDebugRoute parameters and query values are always text. Convert them with Number() before comparing to numbers.
Quick checkQuiz:params and ?query, both as text, and a clear 404 when something is missing.
4. Receive data with POST
Sign-ups, new posts, high scores: apps send data to the server. Read it, check it, save it, and answer 201 or 400.
Echo what you getExerciseapp.use(express.json()) reads JSON bodies, and req.body holds the data. app.post answers POST requests.
The body that never arrivedDebugNo express.json(), no req.body. And a crash inside a route becomes a 500.
Save a high scoreExerciseValidate the body, answer 400 for bad input, 201 for something created.
Quick checkQuizPOST + express.json() + req.body, and status codes that tell the truth: 201, 400, 500.
5. A full REST API
Read, create, update and delete: a complete to-do API, with middleware that logs every request and protects private routes.
A to-do APIExerciseSame address, different methods: GET reads, POST creates, DELETE removes. 204 means "done, nothing to send back".
Middleware that logsExerciseMiddleware runs for every request before the routes. next() continues to the next step.
Protect the admin routeExerciseMiddleware on a single route guards it. 401 means "who are you? you are not allowed".
Quick checkQuizREST: addresses for things, methods for actions. Middleware for logging and security.
6. Backend exam
Ten questions about servers, routes, JSON and REST. Pass with 8 right answers.
The backend examExamYou can build, test and secure a real API with Node.js and Express.
7. Final project
Build a real API for a topic you love, test it with requests, and send it for review.
Your own APIFinal projectList, read one, create, and a correct 404: the core of every real API.
How the course works
You learn by doing: each lesson explains one idea, then you write real code in the editor and see the result right away. The first lesson is free to try without an account; sign up to save your progress and continue.
Try it
Change working code and see the result immediately.
Exercise
Complete a task. A checklist confirms each requirement as you type.
Debug
Fix code that is broken on purpose, and learn why it failed.