0
0
Expressframework~10 mins

Creating an Express Router - Interactive Practice

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('[1]');
const router = express.Router();
Drag options to blanks, or click blank then click option'
Arouter
Bhttp
Cexpress
Dpath
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.
2fill in blank
medium

Complete 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'
Alisten
Bpost
Cuse
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' will expect data to be sent, not retrieved.
Using 'use' is for middleware, not route methods.
3fill in blank
hard

Fix the error in exporting the router.

Express
module.exports = [1];
Drag options to blanks, or click blank then click option'
Aexpress
Brouter
Crequire
Dapp
Attempts:
3 left
💡 Hint
Common Mistakes
Exporting 'express' or 'app' will not export your router routes.
Using 'require' here is incorrect syntax.
4fill in blank
hard

Fill 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'
Ause
Brouter
Cget
Dlisten
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.
5fill in blank
hard

Fill 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'
Apost
Bsend
Crouter
Dget
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.