Recall & Review
beginner
What is an Express Router used for?
An Express Router helps organize routes by grouping related route handlers together. It makes the code cleaner and easier to manage, like having different folders for different topics.
Click to reveal answer
beginner
How do you create a new Express Router?
Use <code>const router = require('express').Router();</code> or <code>const router = express.Router();</code> after importing Express. This creates a mini app to define routes separately.Click to reveal answer
beginner
How do you add a GET route to an Express Router?
Use
router.get('/path', (req, res) => { ... }). This sets a handler for GET requests on the specified path inside the router.Click to reveal answer
beginner
How do you use an Express Router in your main app?
Use
app.use('/prefix', router); to tell the main app to use the router for routes starting with the prefix. This connects the router to the app.Click to reveal answer
beginner
Why is using Express Router better than putting all routes in one file?
It keeps code organized and easier to read. Like sorting books by topic, routers help separate routes by feature or area, making maintenance simpler.
Click to reveal answer
How do you create a new Express Router?
✗ Incorrect
The correct way is to call express.Router() after importing express.
Which method adds a GET route to an Express Router?
✗ Incorrect
router.get() defines a handler for GET requests on a route.
How do you connect a router to the main Express app with a prefix '/api'?
✗ Incorrect
app.use('/api', router) mounts the router on the '/api' path.
What is the main benefit of using Express Router?
✗ Incorrect
Express Router helps organize routes by grouping related ones together.
Which of these is NOT a valid way to define a route on a router?
✗ Incorrect
router.listen() is not a method; listening is done on the main app, not the router.
Explain how to create and use an Express Router in a simple app.
Think of router as a mini app for routes.
You got /4 concepts.
Why should you use Express Router instead of putting all routes in one file?
Compare it to organizing files in folders.
You got /4 concepts.