Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import Express in your Node.js file.
Express
const express = require([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the quotes around the package name.
Using a wrong package name like 'http' or 'fs'.
✗ Incorrect
You need to require the express package by its name as a string to use it in your file.
2fill in blank
mediumComplete the code to create an Express app 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()' instead of 'express()'.
Using 'app()' before defining it.
✗ Incorrect
Calling express() creates a new Express application.
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 instead of a number.
Passing the app or express instead of a port number.
✗ Incorrect
The port number should be a number, not a string, when passed to listen.
4fill in blank
hardFill both blanks to create a GET route for the home page 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 simple page load.
Using '/home' instead of '/' for the main page.
✗ Incorrect
The get method defines a GET route, and '/' is the root path for the home page.
5fill in blank
hardFill all three blanks to import Express, create an app, and start the server on port 5000.
Express
const [1] = require('[2]'); const app = [3](); app.listen(5000, () => { console.log('Server started on port 5000'); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' instead of 'express' for import.
Calling 'http()' instead of 'express()'.
✗ Incorrect
You import the 'express' package, assign it to a variable named 'express', then call it to create the app.