Recall & Review
beginner
Why should you separate routes into different files in an Express app?
Separating routes keeps code organized and easier to manage, especially as the app grows. It helps avoid a big messy file and makes it simpler to find and update routes.
Click to reveal answer
beginner
What Express feature helps you create routes in separate files?
Express Router lets you create modular route handlers in separate files. You can define routes on a router and then use it in your main app file.
Click to reveal answer
intermediate
How do you use a router from another file in your main Express app?
You export the router from the route file using module.exports, then import it in your main app file with require(), and use app.use() to add it to your app.Click to reveal answer
intermediate
What is the purpose of app.use('/path', router) in Express?
It tells Express to use the routes defined in the router for any requests starting with '/path'. This prefixes all routes in the router with '/path'.
Click to reveal answer
beginner
Show a simple example of creating and exporting a router in a separate file.
In routes.js:
const express = require('express');
const router = express.Router();
router.get('/', (req, res) => res.send('Hello from router!'));
module.exports = router;Click to reveal answer
What Express method creates a new router to separate routes into files?
✗ Incorrect
express.Router() creates a new router object to define routes separately.
How do you add routes from a router file to your main Express app?
✗ Incorrect
app.use('/path', router) mounts the router on the specified path.
Which keyword exports the router from a separate file in Node.js?
✗ Incorrect
module.exports is used to export objects like routers in Node.js.
If your router has a route '/list' and you use app.use('/items', router), what is the full path to access the route?
✗ Incorrect
The router path '/list' is prefixed by '/items' from app.use, making '/items/list'.
Why is separating routes into files helpful in Express apps?
✗ Incorrect
Separating routes helps organize code and makes maintenance easier.
Explain how to separate routes into files in an Express app and how to use them in the main app.
Think about creating a mini app inside a file and connecting it to the main app.
You got /5 concepts.
Describe the benefits of separating routes into different files in Express.
Consider how you organize things in real life to keep them neat and easy to find.
You got /5 concepts.