0
0
Expressframework~10 mins

Repository pattern for data access 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 Express module.

Express
const express = require('[1]');
Drag options to blanks, or click blank then click option'
Afs
Bexpress
Chttp
Dpath
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' instead of 'express'.
Forgetting to put quotes around the module name.
2fill in blank
medium

Complete the code to create a new Express Router instance.

Express
const router = express.[1]();
Drag options to blanks, or click blank then click option'
Aapp
Bserver
Croute
DRouter
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'route' instead of 'Router'.
Using 'app' which is for the main app, not router.
3fill in blank
hard

Fix 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'
Afind
Binsert
Cdelete
DfindOne
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'findOne' which returns a single user.
Using 'insert' which adds data instead of retrieving.
4fill in blank
hard

Fill 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'
Aid
BuserId
C_id
Duser_id
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'.
5fill in blank
hard

Fill 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'
Aid
Bdata
C_id
DuserData
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing parameter names like 'userData' instead of 'data'.
Using wrong query key like 'user_id' instead of '_id'.