Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Express module.
Express
const express = require('[1]');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'router' or 'routes' instead of 'express'.
Leaving the string empty.
✗ Incorrect
You need to import the 'express' module to use Express features.
2fill in blank
mediumComplete the code to create a new router instance.
Express
const router = express.[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'route' instead of 'Router'.
Using lowercase 'router'.
✗ Incorrect
The method to create a router is express.Router() with a capital R.
3fill in blank
hardFix the error in exporting the router from the routes file.
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'.
Forgetting to export anything.
✗ Incorrect
You export the router instance so it can be used in other files.
4fill in blank
hardFill both blanks to import and use the router in the main app file.
Express
const [1] = require('./routes'); app.use([2]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'express' instead of the router variable.
Mixing variable names between import and use.
✗ Incorrect
You import the router as 'router' and then use it with app.use(router).
5fill in blank
hardFill all three blanks to define a GET route in the router file.
Express
router.[1]('[2]', (req, res) => { res.[3]('Hello from route!'); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' instead of 'get'.
Forgetting the slash in the path.
Using 'res.sendFile' instead of 'res.send'.
✗ Incorrect
Use router.get to define a GET route, specify the path '/hello', and respond with res.send.