Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import Express and create a router.
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'
Using 'route' which is incorrect
✗ Incorrect
Use express.Router() to create a modular router instance.
2fill in blank
mediumComplete the code to define a GET route on the router.
Express
router.[1]('/', (req, res) => { res.send('Hello from modular route!'); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' instead of 'get'
Using 'use' which is for middleware
✗ Incorrect
The get method defines a GET route handler.
3fill in blank
hardFix the error in exporting the router from the module.
Express
module.exports = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Exporting 'express' or 'app' instead of 'router'
✗ Incorrect
Export the router instance to use it in other files.
4fill in blank
hardFill both blanks to mount the modular router in the main app.
Express
const express = require('express'); const app = express(); const userRoutes = require('./routes/users'); app.[1]('/users', [2]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'listen' instead of 'use'
Passing wrong variable instead of router
✗ Incorrect
Use app.use to mount the router at the '/users' path.
5fill in blank
hardFill all three blanks to create a modular route that handles POST requests and exports correctly.
Express
const express = require('express'); const router = express.[1](); router.[2]('/submit', (req, res) => { res.send('Form submitted'); }); module.exports = [3];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'router()' to create router
Using 'route' instead of 'post'
Exporting wrong variable
✗ Incorrect
Create a router with Router(), define a POST route with post, and export the router.