0
0
Expressframework~10 mins

How Express builds on Node.js HTTP - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Alisten
Bget
Cuse
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'listen' instead of 'get' to define a route.
2fill in blank
medium

Complete 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'
Alisten
Bstart
Crun
Dopen
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'start' or 'run' which are not Express methods.
3fill in blank
hard

Fix 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'
Aapp
Bapp.listen()
Cexpress()
Dhttp
Attempts:
3 left
💡 Hint
Common Mistakes
Passing app.listen() which starts the server instead of passing app.
4fill in blank
hard

Fill 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'
Aexpress
Bapp
Chttp
Dlisten
Attempts:
3 left
💡 Hint
Common Mistakes
Passing 'http' instead of 'app' to createServer.
5fill in blank
hard

Fill 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'
Aget
Bsend
Clisten
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' instead of 'get' for the route.