0
0
Expressframework~10 mins

Separating routes into files in Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Express module.

Express
const express = require('[1]');
Drag options to blanks, or click blank then click option'
Aexpress
Brouter
Croutes
Dapp
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'router' or 'routes' instead of 'express'.
Leaving the string empty.
2fill in blank
medium

Complete the code to create a new router instance.

Express
const router = express.[1]();
Drag options to blanks, or click blank then click option'
Aroute
Bapp
Croutes
DRouter
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'route' instead of 'Router'.
Using lowercase 'router'.
3fill in blank
hard

Fix the error in exporting the router from the routes file.

Express
module.exports = [1];
Drag options to blanks, or click blank then click option'
Arouter
Bapp
Cexpress
Droutes
Attempts:
3 left
💡 Hint
Common Mistakes
Exporting 'express' or 'app' instead of 'router'.
Forgetting to export anything.
4fill in blank
hard

Fill 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'
Arouter
Broutes
Dexpress
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'express' instead of the router variable.
Mixing variable names between import and use.
5fill in blank
hard

Fill 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'
Aget
B/hello
Csend
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' instead of 'get'.
Forgetting the slash in the path.
Using 'res.sendFile' instead of 'res.send'.