Challenge - 5 Problems
Express GET Endpoint Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the response body of this GET endpoint?
Consider this Express GET endpoint. What will the client receive as the response body when requesting
/hello?Express
const express = require('express'); const app = express(); app.get('/hello', (req, res) => { res.json({ message: 'Hello, world!' }); });
Attempts:
2 left
💡 Hint
Look at the method used to send the response and the object passed.
✗ Incorrect
The endpoint uses res.json() to send a JSON object with a key 'message' and value 'Hello, world!'. So the client receives {"message":"Hello, world!"}.
📝 Syntax
intermediate2:00remaining
Which option correctly defines a GET endpoint that sends plain text?
Which code snippet correctly defines a GET endpoint at
/text that sends the plain text response "Hello"?Attempts:
2 left
💡 Hint
Check the Express method that sends plain text responses.
✗ Incorrect
res.send() sends plain text or HTML. res.json() sends JSON. res.sendJson and res.sendText are not valid Express methods.
🔧 Debug
advanced2:00remaining
Why does this GET endpoint cause a runtime error?
Examine the code below. Why will a GET request to
/data cause a runtime error?Express
app.get('/data', (req, res) => {
const data = undefined;
res.json(data.value);
});Attempts:
2 left
💡 Hint
What happens if you try to access a property of undefined?
✗ Incorrect
Accessing a property on undefined causes a TypeError at runtime.
❓ state_output
advanced2:00remaining
What is the response after multiple GET requests?
Given this Express app, what will be the response body of the third GET request to
/count?Express
let count = 0; app.get('/count', (req, res) => { count += 1; res.json({ count }); });
Attempts:
2 left
💡 Hint
The variable count increases by 1 on each request.
✗ Incorrect
Each GET request increments count by 1. On the third request, count is 3.
🧠 Conceptual
expert3:00remaining
Which option correctly explains why this GET endpoint never sends a response?
Consider this Express GET endpoint. Why does a client request to
/never hang indefinitely?Express
app.get('/never', (req, res) => { if (false) { res.send('Done'); } // no else or res.send outside if });
Attempts:
2 left
💡 Hint
Think about what happens if no response method is called in Express.
✗ Incorrect
If no response method like res.send or res.end is called, the client waits forever because the server never finishes the response.