Recall & Review
beginner
What is route prefixing in Express?
Route prefixing means adding a common path segment to a group of routes, so you don't repeat it for each route. It helps organize routes better.
Click to reveal answer
beginner
How do you apply a route prefix using Express Router?
You create a router with express.Router(), define routes on it, then use app.use('/prefix', router) to add the prefix to all routes inside the router.
Click to reveal answer
beginner
Why is route prefixing useful in Express apps?
It keeps code clean by grouping related routes under one path. It also makes it easier to change the base path later without editing every route.
Click to reveal answer
beginner
Example: What is the full path for a route defined as router.get('/list') if the router is used with app.use('/users', router)?
The full path is '/users/list' because '/users' is the prefix added to all routes in that router.
Click to reveal answer
intermediate
Can you use multiple route prefixes in Express?
Yes, you can nest routers and apply different prefixes at each level to build complex route structures.
Click to reveal answer
What does app.use('/api', router) do in Express?
✗ Incorrect
app.use('/api', router) adds '/api' as a prefix to all routes inside the router.
If router has route router.get('/profile'), and you use app.use('/user', router), what URL matches this route?
✗ Incorrect
The prefix '/user' is added before '/profile', so the full path is '/user/profile'.
Which Express method creates a modular route handler for prefixing?
✗ Incorrect
express.Router() creates a router object to define routes that can be prefixed.
What happens if you call app.use(router) without a path prefix?
✗ Incorrect
Without a prefix, routes are mounted at the root path '/' by default.
Can route prefixing help with API versioning?
✗ Incorrect
Prefixing routes with versions like '/v1' helps organize and manage API versions.
Explain how route prefixing works in Express and why it is useful.
Think about how you can add a common path to many routes at once.
You got /5 concepts.
Describe a scenario where nested route prefixing would be helpful in an Express app.
Imagine building an API with sections for users and products.
You got /4 concepts.