Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create an Express app instance.
Express
const express = require('express'); const app = express(); app.[1]('/', (req, res) => { res.send('Hello World'); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'listen' instead of 'get' to define a route.
✗ Incorrect
The get method defines a route handler for GET requests on the root path.
2fill in blank
mediumComplete the code to start the Express server on port 3000.
Express
app.[1](3000, () => { console.log('Server running on port 3000'); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start' or 'run' which are not Express methods.
✗ Incorrect
The listen method starts the server and listens on the specified port.
3fill in blank
hardFix the error in the code to correctly create an HTTP server using Express.
Express
const http = require('http'); const express = require('express'); const app = express(); const server = http.createServer([1]); server.listen(3000);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing app.listen() which starts the server instead of passing app.
✗ Incorrect
The http.createServer method expects a request listener function, which Express app provides.
4fill in blank
hardFill both blanks to create an Express app and start the HTTP server on port 4000.
Express
const http = require('http'); const express = require('express'); const app = [1](); const server = http.createServer([2]); server.listen(4000);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing 'http' instead of 'app' to createServer.
✗ Incorrect
First, call express() to create the app. Then pass app to createServer.
5fill in blank
hardFill all three blanks to define a GET route and start the Express server on port 5000.
Express
const express = require('express'); const app = express(); app.[1]('/hello', (req, res) => { res.[2]('Hello Express'); }); app.[3](5000, () => { console.log('Server listening on port 5000'); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' instead of 'get' for the route.
✗ Incorrect
Use get to define the route, send to respond, and listen to start the server.