Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to mount the router on the '/api' path.
Express
const express = require('express'); const app = express(); const router = require('./router'); app.[1]('/api', router);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using app.get or app.post instead of app.use to mount routers.
Trying to call app.listen instead of mounting the router.
✗ Incorrect
Use app.use to mount a router on a path prefix.
2fill in blank
mediumComplete the code to create a new router instance.
Express
const express = require('express'); const router = express.[1]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'router' instead of 'Router'.
Trying to call express.app() or express.use() to create a router.
✗ Incorrect
Use express.Router() to create a new router instance.
3fill in blank
hardFix the error in mounting the router on the '/users' path.
Express
const express = require('express'); const app = express(); const usersRouter = require('./usersRouter'); app.[1]('/users', usersRouter);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using app.get or app.post instead of app.use to mount routers.
Trying to call app.listen instead of mounting the router.
✗ Incorrect
To mount a router on a path, use app.use, not app.get or app.post.
4fill in blank
hardFill both blanks to mount a router that handles '/products' routes.
Express
const express = require('express'); const app = express(); const [1] = express.Router(); app.[2]('/products', [1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using app.get instead of app.use to mount the router.
Using a generic router name instead of a descriptive one.
✗ Incorrect
Create a router named productsRouter and mount it with app.use on '/products'.
5fill in blank
hardFill all three blanks to create and mount a router for '/orders' routes.
Express
const express = require('express'); const app = express(); const [1] = express.[2](); app.[3]('/orders', [1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'router' instead of 'Router' when creating the router.
Using app.get or app.post instead of app.use to mount the router.
✗ Incorrect
Create a router named ordersRouter using express.Router() and mount it with app.use on '/orders'.