Express basics · core
Routing, params, query and Router
Express matches routes in the order you register them, by method and path, puts path parameters in req.params and the query string in req.query, and lets you group routes with express.Router mounted at a prefix.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- app.get/post/put/patch/delete(path, ...handlers); app.all for any method. app.use(path, fn) matches any method and any path that starts with that prefix (/api and /api/users, not /apix).
- express.Router() is a mini-app: app.use('/api/users', usersRouter) mounts it, and paths inside the router are relative ('/:id').
- Order matters: register '/users/me' before '/users/:id', or 'me' is treated as an id.
- req.params values are always strings ('42'): validate and convert them. In Express 5, req.query uses the 'simple' parser by default (no nested objects) and is a read-only getter.
- Express 5 path syntax: wildcards need a name ('/*splat'; '/{*splat}' also matches the root), optional parts use braces ('/:file{.:ext}'), no regex inside path strings (use an array of paths), and ( ) [ ] ? + ! are reserved.
- Add a final 404 handler after all routes for requests nothing matched.
- Resource-style URLs: plural nouns, nested one level at most (/users/:id/orders).
The red pen
Common traps: mistake → fix
Mistake: Route order does not matter
Fix: the first matching route wins; put specific paths before parameter paths.
Mistake: req.params.id is a number
Fix: it is always a string; validate and convert it.
Mistake: app.get('/*') still works in Express 5
Fix: unnamed wildcards throw; write '/*splat'.
Easy to hard
Questions interviewers ask, easy to hard
- How does Express decide which handler runs for a request?
- app.use vs app.get: what is the difference?
- What is express.Router and why use it?
- Why does GET /users/me return 'user not found'?
- What changed in route path syntax in Express 5?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.