Recall & Review
beginner
What is a virtual path prefix in Express?
A virtual path prefix is a path segment added before the actual route path when mounting middleware or routers. It helps organize routes under a common base URL without repeating the prefix in each route.
Click to reveal answer
beginner
How do you use a virtual path prefix with an Express router?
You use app.use('/prefix', router) to mount the router so all routes inside the router are accessed under '/prefix'. For example, if router has '/users', the full path becomes '/prefix/users'.
Click to reveal answer
beginner
Why use virtual path prefixes instead of writing full paths in each route?
Virtual path prefixes keep code cleaner and easier to maintain by grouping related routes under one base path. It avoids repeating the same prefix in every route definition.
Click to reveal answer
beginner
Example: What URL path will respond if you mount a router with app.use('/api', router) and router has router.get('/items')?
The URL path '/api/items' will respond because '/api' is the virtual prefix and '/items' is the route inside the router.
Click to reveal answer
intermediate
Can virtual path prefixes be nested in Express?
Yes, you can nest routers with their own prefixes. For example, app.use('/api', apiRouter) and inside apiRouter you use apiRouter.use('/v1', v1Router). The full path becomes '/api/v1/...'.
Click to reveal answer
What does app.use('/admin', adminRouter) do in Express?
✗ Incorrect
app.use('/admin', adminRouter) mounts the router so all routes inside adminRouter are prefixed with '/admin'.
If router has router.get('/profile'), and you mount it with app.use('/user', router), what URL path responds?
✗ Incorrect
The virtual prefix '/user' is added before '/profile', so the full path is '/user/profile'.
Why are virtual path prefixes useful?
✗ Incorrect
Virtual path prefixes help organize routes by grouping them under a shared base URL.
Can you mount multiple routers with different virtual prefixes in Express?
✗ Incorrect
You can mount many routers each with different virtual path prefixes to organize routes.
What happens if you mount a router without a virtual path prefix like app.use(router)?
✗ Incorrect
Mounting without a prefix means routes are accessible directly at their defined paths from the root.
Explain what a virtual path prefix is in Express and why it is helpful.
Think about grouping routes under one common URL segment.
You got /3 concepts.
Describe how you would use virtual path prefixes to organize routes for an API with versions like /api/v1 and /api/v2.
Consider nesting routers with app.use calls.
You got /3 concepts.