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 other module names like 'http' or 'fs' instead of 'express'.
Forgetting the quotes around the module name.
✗ Incorrect
To use Express, you must require the 'express' package by its exact name.
2fill in blank
mediumComplete the code to create a new Express application instance.
Express
const app = [1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' or 'server' instead of 'express'.
Forgetting the parentheses after the function name.
✗ Incorrect
Calling the imported 'express' function creates a new app instance.
3fill in blank
hardFix the error in the test setup function to connect to the test database.
Express
beforeAll(async () => {
await [1].connect('mongodb://localhost/testdb');
}); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to connect using 'app' or 'express' which are for the server.
Using 'http' which is unrelated to database connections.
✗ Incorrect
Use the 'mongoose' library to connect to MongoDB in tests.
4fill in blank
hardFill both blanks to properly close the database connection after tests.
Express
afterAll(async () => {
await [1].[2]();
}); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'app.close()' which closes the server, not the database.
Using 'mongoose.close()' which is not a valid method.
✗ Incorrect
Use 'mongoose.disconnect()' to close the database connection after tests.
5fill in blank
hardFill all three blanks to set up and tear down a test database connection correctly.
Express
beforeAll(async () => {
await [1].connect('mongodb://localhost/testdb');
});
afterAll(async () => {
await [2].[3]();
}); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'app' instead of 'mongoose' for database operations.
Using 'close' instead of 'disconnect' to close the database.
✗ Incorrect
Use 'mongoose.connect()' to connect and 'mongoose.disconnect()' to close the database connection in tests.