0
0
Expressframework~10 mins

Why modular routing matters in Express - Test Your Understanding

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

Complete 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'
Aapp
Brouter
Croute
DRouter
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'router' instead of 'Router'
Using 'route' which is incorrect
2fill in blank
medium

Complete 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'
Apost
Bget
Cuse
Dlisten
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' instead of 'get'
Using 'use' which is for middleware
3fill in blank
hard

Fix the error in exporting the router from the module.

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

Fill 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'
Ause
Blisten
CuserRoutes
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'listen' instead of 'use'
Passing wrong variable instead of router
5fill in blank
hard

Fill 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'
ARouter
Bpost
Crouter
Droute
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'router()' to create router
Using 'route' instead of 'post'
Exporting wrong variable