Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import Express and create a router.
Express
const express = require('[1]'); const router = express.Router();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' instead of 'express' will not provide the router function.
Using 'path' or 'router' as module names will cause errors.
✗ Incorrect
You need to import the 'express' module to create a router.
2fill in blank
mediumComplete the code to define a GET route on the router.
Express
router.[1]('/', (req, res) => { res.send('Hello from router!'); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' will expect data to be sent, not retrieved.
Using 'use' is for middleware, not route methods.
✗ Incorrect
The 'get' method defines a route that responds to GET requests.
3fill in blank
hardFix the error in exporting the router.
Express
module.exports = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Exporting 'express' or 'app' will not export your router routes.
Using 'require' here is incorrect syntax.
✗ Incorrect
You export the router object so other files can use it.
4fill in blank
hardFill both blanks to mount the router on the app at '/api'.
Express
const app = express(); app.[1]('/api', [2]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'use' will not mount the router correctly.
Passing 'listen' or 'app' instead of the router will cause errors.
✗ Incorrect
Use app.use to mount the router middleware at the '/api' path.
5fill in blank
hardFill all three blanks to create a router with a POST route and export it.
Express
const express = require('express'); const router = express.Router(); router.[1]('/submit', (req, res) => { res.[2]('Data received'); }); module.exports = [3];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'post' changes the route behavior.
Forgetting to export the router will make it unusable elsewhere.
✗ Incorrect
This code defines a POST route on the router and exports it for use in other files.