0
0
Expressframework~10 mins

Namespaces for separation 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 create a new router instance in Express.

Express
const router = require('express').[1]();
Drag options to blanks, or click blank then click option'
Alisten
Broute
Capp
DRouter
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'route' instead of 'Router' causes an error.
Using 'app' is for the main app, not routers.
2fill in blank
medium

Complete the code to mount the router under the '/api' namespace.

Express
app.[1]('/api', router);
Drag options to blanks, or click blank then click option'
Ause
Bget
Cpost
Dlisten
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' or 'post' only handles those HTTP methods.
Using 'listen' is for starting the server.
3fill in blank
hard

Fix the error in the router code to define a GET route at '/' inside the router.

Express
router.[1]('/', (req, res) => { res.send('Hello from API'); });
Drag options to blanks, or click blank then click option'
Aget
Buse
Cpost
Dlisten
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' handles POST requests, not GET.
Using 'use' is for middleware, not specific HTTP methods.
4fill in blank
hard

Fill both blanks to create a router and export it for use in the main app.

Express
const [1] = require('express').Router();
module.exports = [2];
Drag options to blanks, or click blank then click option'
Arouter
Bapp
Cserver
Dexpress
Attempts:
3 left
💡 Hint
Common Mistakes
Exporting 'app' instead of 'router' causes errors.
Using 'express' as the export is incorrect.
5fill in blank
hard

Fill all three blanks to define a namespaced route that responds with JSON.

Express
const [1] = require('express').Router();

[1].[2]('/status', (req, res) => {
  res.[3]({ message: 'API is running' });
});
Drag options to blanks, or click blank then click option'
Arouter
Bget
Cjson
Dsend
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'send' instead of 'json' sends plain text.
Using 'post' instead of 'get' changes the HTTP method.