

Lesson 01 · 11 min
Routes, req, and res
A route is a method + a path + a function. req is what came in, res is what goes out.
11 minLesson 1 of 9Practice includedAsk AI on any point
Express is a minimal framework over Node's HTTP server. You register a route: a method, a path, and a handler (req, res) => …. req.params holds path parts like :id, req.query the query, req.body the parsed body.
req.params.idis always a string. To match a number, convert it:Number(id).res.status(201).json(data)chains the status and body.- Without
express.json(),req.bodyis undefined.
Check
Lock it in before you move on
1. Route
/users/:id, request/users/5. What's inreq.params.id?2. What happens if you call
res.jsontwice?3.
req.bodyis empty though the client sent JSON. What's missing?