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
The Express module is imported using require("express"). This allows you to create an Express app.
2fill in blank
mediumComplete the code to create an Express application instance.
Express
const app = [1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call 'http()' or 'server()' instead of 'express()'.
Using 'router()' which is for routing, not app creation.
✗ Incorrect
You create an Express app by calling the express() function.
3fill in blank
hardFix the error in the code to start the server on port 3000.
Express
app.listen([1], () => { console.log('Server running on port 3000'); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the port as a string like '3000' instead of number 3000.
Passing the app or express variable instead of a port number.
✗ Incorrect
The port number should be a number, not a string. So use 3000 without quotes.
4fill in blank
hardFill both blanks to define a GET route for the root URL that sends 'Hello World'.
Express
app.[1]('[2]', (req, res) => { res.send('Hello World'); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' instead of 'get' for a GET route.
Using '/home' instead of '/' for the root URL.
✗ Incorrect
The get method defines a GET route. The root URL is '/'.
5fill in blank
hardFill all three blanks to import Express, create an app, and start the server on port 4000.
Express
const [1] = require('[2]'); const app = [3](); app.listen(4000, () => { console.log('Server started on port 4000'); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' or 'expressjs' instead of 'express' as module name.
Using different variable names for import and app creation.
✗ Incorrect
You import Express with require('express'), assign it to express, then call express() to create the app.