Recall & Review
beginner
What is a namespace in Express.js?
A namespace in Express.js is a way to group routes under a common path prefix to organize and separate different parts of an application.
Click to reveal answer
beginner
How do you create a namespace for routes in Express?
You create a namespace by using an Express Router and mounting it on a path prefix with app.use('/prefix', router).
Click to reveal answer
beginner
Why use namespaces (route prefixes) in Express applications?
Namespaces help keep routes organized, avoid route conflicts, and make the code easier to maintain by grouping related routes together.
Click to reveal answer
intermediate
Example: What does this code do?
const router = express.Router();
router.get('/list', ...);
app.use('/users', router);It creates a namespace '/users' so that the route '/users/list' is handled by the router's get method.
Click to reveal answer
intermediate
Can namespaces in Express be nested? How?
Yes, namespaces can be nested by mounting routers inside other routers with different path prefixes.
Click to reveal answer
What Express method is used to create a namespace for routes?
✗ Incorrect
express.Router() creates a modular router which can be mounted as a namespace.
How do you mount a router under a namespace '/api'?
✗ Incorrect
app.use('/api', router) mounts the router so all its routes are prefixed with '/api'.
What is a benefit of using namespaces in Express?
✗ Incorrect
Namespaces help organize routes logically and avoid conflicts.
If a router has a route '/list' and is mounted at '/users', what is the full route path?
✗ Incorrect
The full path combines the mount point and the router route.
Can you nest routers inside other routers in Express?
✗ Incorrect
Routers can be nested by mounting one router inside another.
Explain how namespaces help organize routes in an Express app.
Think about how grouping routes under a shared path helps keep code tidy.
You got /4 concepts.
Describe the steps to create and use a namespace with Express Router.
Start from making a router, then connect it to the main app.
You got /4 concepts.