Bird
Raised Fist0
Expressframework~20 mins

How Express builds on Node.js HTTP - Practice Exercises

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Express HTTP Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What does this Express middleware do?

Consider this Express middleware function:

app.use((req, res, next) => {
  console.log(req.method);
  next();
});

What will be printed when a GET request is made to the server?

Express
const express = require('express');
const app = express();

app.use((req, res, next) => {
  console.log(req.method);
  next();
});

app.get('/', (req, res) => {
  res.send('Hello');
});

app.listen(3000);
Aundefined
BPOST
CGET
DError
Attempts:
2 left
💡 Hint

Look at the request method property logged.

📝 Syntax
intermediate
2:00remaining
Identify the correct way to create an Express server using Node.js HTTP module

Which option correctly creates an Express app and starts a server using Node.js HTTP module?

Express
const express = require('express');
const http = require('http');
const app = express();
Ahttp.createServer(app.listen(3000));
B
const server = http.createServer(app);
server.listen(3000);
C
app.createServer(http);
app.listen(3000);
D
const server = http.createServer();
server.listen(3000, app);
Attempts:
2 left
💡 Hint

Express apps can be passed as request listeners to Node.js HTTP servers.

🔧 Debug
advanced
2:00remaining
Why does this Express app not respond to requests?

Given this code, why does the server not respond to requests?

const express = require('express');
const app = express();

app.get('/', (req, res) => {
  res.send('Hi');
});

// Missing app.listen call
Express
const express = require('express');
const app = express();

app.get('/', (req, res) => {
  res.send('Hi');
});
AExpress requires a callback in app.get to be async
BThe route handler is incorrect and causes an error
CThe app needs to import http module to work
DThe server never starts listening because app.listen is missing
Attempts:
2 left
💡 Hint

Check if the server is actually listening for requests.

❓ state_output
advanced
2:00remaining
What is the output of this Express app using Node.js HTTP server?

What will be the response body when a client requests '/'?

Express
const express = require('express');
const http = require('http');
const app = express();

app.get('/', (req, res) => {
  res.send('Welcome');
});

const server = http.createServer(app);
server.listen(3000);
AWelcome
BCannot GET /
CError: app is not a function
DEmpty response
Attempts:
2 left
💡 Hint

Express app can be used as a request handler for Node.js HTTP server.

🧠 Conceptual
expert
3:00remaining
How does Express extend Node.js HTTP request and response objects?

Which statement best describes how Express builds on Node.js HTTP module?

AExpress wraps Node.js HTTP request and response objects to add helper methods like res.send and req.params
BExpress replaces Node.js HTTP module with its own implementation
CExpress uses a different protocol than HTTP for requests and responses
DExpress requires manual parsing of request body unlike Node.js HTTP
Attempts:
2 left
💡 Hint

Think about how Express adds convenience methods to the request and response.

Practice

(1/5)
1. What is the main advantage of using Express over the basic Node.js HTTP module?
easy
A. It replaces the HTTP protocol with a new one.
B. It simplifies routing and middleware handling.
C. It automatically creates databases for your app.
D. It runs Node.js code faster by compiling it.

Solution

  1. Step 1: Understand Node.js HTTP module

    The Node.js HTTP module provides basic tools to create servers but requires manual handling of routing and requests.
  2. Step 2: Identify Express features

    Express adds easy routing and middleware support, making it simpler to write web apps without dealing with low-level HTTP details.
  3. Final Answer:

    It simplifies routing and middleware handling. -> Option B
  4. Quick Check:

    Express adds routing and middleware = A [OK]
Hint: Express adds routing and middleware on top of HTTP [OK]
Common Mistakes:
  • Thinking Express changes the HTTP protocol
  • Believing Express creates databases automatically
  • Assuming Express speeds up Node.js runtime
2. Which of the following is the correct way to create an Express app instance?
easy
A. const app = express();
B. const app = express.createApp();
C. const app = new express();
D. const app = express.app();

Solution

  1. Step 1: Recall Express app creation syntax

    Express exports a function that when called returns an app instance, so you use express() directly.
  2. Step 2: Check each option

    const app = express(); uses express() correctly. The other options use invalid methods or constructors.
  3. Final Answer:

    const app = express(); -> Option A
  4. Quick Check:

    Express app created by calling express() [OK]
Hint: Create app by calling express() function [OK]
Common Mistakes:
  • Using new express() instead of express()
  • Trying express.createApp() which doesn't exist
  • Calling express.app() which is invalid
3. Given this Express code snippet, what will be the response when a GET request is made to '/'?
const express = require('express');
const app = express();
app.get('/', (req, res) => {
  res.send('Hello World');
});
app.listen(3000);
medium
A. The server throws an error because listen is missing a callback.
B. The server responds with an empty page.
C. The server responds with 'Hello World'.
D. The server crashes due to missing middleware.

Solution

  1. Step 1: Analyze the route handler

    The app defines a GET route for '/' that sends 'Hello World' as the response.
  2. Step 2: Check server listen and response

    Calling app.listen(3000) starts the server; no callback is required for it to work. The response will be 'Hello World'.
  3. Final Answer:

    The server responds with 'Hello World'. -> Option C
  4. Quick Check:

    GET '/' sends 'Hello World' [OK]
Hint: GET '/' route sends 'Hello World' response [OK]
Common Mistakes:
  • Thinking listen needs a callback to work
  • Assuming missing middleware causes crash
  • Expecting empty response without send()
4. What is wrong with this Express code snippet?
const express = require('express');
const app = express();
app.get('/hello', (req, res) => {
  res.send('Hi there!');
});
app.listen(3000)
console.log('Server started');
medium
A. Missing semicolon after app.listen(3000) causes syntax error.
B. The server will not respond because app.listen lacks a callback.
C. The route handler uses res.send incorrectly.
D. The code works fine; no errors present.

Solution

  1. Step 1: Check syntax and semicolons

    JavaScript does not require semicolons strictly; missing one here does not cause an error.
  2. Step 2: Verify app.listen and route handler

    app.listen without a callback works fine. res.send is used correctly to send a response.
  3. Final Answer:

    The code works fine; no errors present. -> Option D
  4. Quick Check:

    Missing semicolon is allowed; code runs [OK]
Hint: Missing semicolons often don't cause errors in Node.js [OK]
Common Mistakes:
  • Assuming missing semicolon causes syntax error
  • Thinking app.listen needs a callback to work
  • Believing res.send usage is incorrect here
5. How does Express simplify handling multiple routes compared to using Node.js HTTP module directly?
hard
A. Express lets you define routes with app.get/post methods instead of manual URL checks.
B. Express automatically generates HTML pages for each route.
C. Express replaces HTTP methods with custom ones for easier coding.
D. Express requires you to write more code to handle each route.

Solution

  1. Step 1: Understand Node.js HTTP routing

    Using Node.js HTTP module, you must manually check request URLs and methods to handle routes.
  2. Step 2: Understand Express routing

    Express provides app.get(), app.post(), etc., to define routes clearly and simply without manual URL parsing.
  3. Final Answer:

    Express lets you define routes with app.get/post methods instead of manual URL checks. -> Option A
  4. Quick Check:

    Express routing uses app.get/post for easy route handling [OK]
Hint: Express uses app.get/post for easy route setup [OK]
Common Mistakes:
  • Thinking Express auto-generates HTML pages
  • Believing Express changes HTTP methods
  • Assuming Express requires more code for routes
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard