Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Express module.
Express
const express = require('[1]');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' instead of 'express'.
Forgetting to put quotes around the module name.
✗ Incorrect
The Express module is imported by requiring 'express'.
2fill in blank
mediumComplete the code to create a new Express Router instance.
Express
const router = express.[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'route' instead of 'Router'.
Using 'app' which is for the main app, not router.
✗ Incorrect
Express Router is created by calling express.Router().
3fill in blank
hardFix the error in the repository method to return all users.
Express
async getAllUsers() {
return await this.db.[1]('users');
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'findOne' which returns a single user.
Using 'insert' which adds data instead of retrieving.
✗ Incorrect
The method to get all documents is 'find'.
4fill in blank
hardFill both blanks to define a repository method that finds a user by ID.
Express
async getUserById([1]) { return await this.db.findOne([2]: id); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'userId' as parameter but not matching query key.
Using 'id' parameter but wrong query key like 'user_id'.
✗ Incorrect
The method parameter is 'id' and the query key is '_id' to find by MongoDB ID.
5fill in blank
hardFill all three blanks to create a repository method that updates a user by ID.
Express
async updateUser([1], [2]) { return await this.db.updateOne([3]: id}, { $set: data }); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing parameter names like 'userData' instead of 'data'.
Using wrong query key like 'user_id' instead of '_id'.
✗ Incorrect
The method takes 'id' and 'data' as parameters, and uses '_id' as the query key to update the user.