0
0
Expressframework~10 mins

Controller pattern for route handlers 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 controller module correctly.

Express
const userController = require('[1]');
Drag options to blanks, or click blank then click option'
Arouter
Bexpress
Chttp
D./userController
Attempts:
3 left
💡 Hint
Common Mistakes
Using a package name instead of a local file path.
Forgetting the './' prefix for local files.
2fill in blank
medium

Complete the code to define a GET route using the controller's method.

Express
router.get('/users', [1].getAllUsers);
Drag options to blanks, or click blank then click option'
Aapp
BuserController
Crouter
Dexpress
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'app' or 'express' instead of the controller object.
Using 'router' instead of the controller for the handler.
3fill in blank
hard

Fix the error in the controller method export syntax.

Express
module.exports = { [1]: (req, res) => { res.send('Hello'); } };
Drag options to blanks, or click blank then click option'
AgetAllUsers
Bexports
Cmodule
Drequire
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'exports' or 'module' as keys instead of method names.
Using 'require' which is for importing, not exporting.
4fill in blank
hard

Fill both blanks to create a POST route and call the correct controller method.

Express
router.[1]('/users', [2].createUser);
Drag options to blanks, or click blank then click option'
Apost
BuserController
Cget
Dapp
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'post' for POST routes.
Using 'app' instead of the controller object.
5fill in blank
hard

Fill all three blanks to export the router and import express and the controller correctly.

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

router.get('/users', userController.getAllUsers);

module.exports = [3];
Drag options to blanks, or click blank then click option'
Aexpress
B./userController
Crouter
Dapp
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'app' instead of 'router' for export.
Forgetting './' in the controller import path.