Challenge - 5 Problems
HTTP Server Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Why do we use HTTP servers in Node.js?
Which of the following best explains why building HTTP servers is important in Node.js?
Attempts:
2 left
💡 Hint
Think about what happens when you open a website in your browser.
✗ Incorrect
HTTP servers listen for requests from browsers or other clients and send back responses like web pages or data. This is how websites and web apps work.
❓ component_behavior
intermediate2:00remaining
What happens when a Node.js HTTP server receives a request?
Consider a simple Node.js HTTP server. What does the server do when it receives a request from a browser?
Attempts:
2 left
💡 Hint
Think about what a web server's job is when you visit a website.
✗ Incorrect
The server listens for requests, processes them, and sends back responses so the browser can show the web page or data.
📝 Syntax
advanced2:30remaining
Identify the correct way to create a basic HTTP server in Node.js
Which code snippet correctly creates a simple HTTP server that responds with 'Hello World'?
Node.js
const http = require('http');
// Choose the correct server creation code belowAttempts:
2 left
💡 Hint
Remember to send a status code and end the response properly.
✗ Incorrect
Option C correctly sets the status code with writeHead and ends the response with the message. Option C misses the status code. Option C uses a method not available on the response object. Option C does not end the response, so the client waits forever.
🔧 Debug
advanced2:30remaining
Why does this Node.js HTTP server code cause the browser to hang?
Look at this code snippet:
const http = require('http');
const server = http.createServer((req, res) => {
res.write('Loading...');
});
server.listen(3000);
Why does the browser keep loading and never show the response?
Attempts:
2 left
💡 Hint
Think about how HTTP responses are completed.
✗ Incorrect
The response must be ended with res.end() to tell the browser the message is complete. Without it, the browser waits forever.
❓ state_output
expert3:00remaining
What is the output when multiple requests hit this Node.js HTTP server?
Consider this server code:
const http = require('http');
let count = 0;
const server = http.createServer((req, res) => {
count++;
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(`Request number: ${count}`);
});
server.listen(3000);
If three requests come in one after another, what will the third request receive as a response?
Attempts:
2 left
💡 Hint
Think about how the variable count changes with each request.
✗ Incorrect
The variable count increments with each request, so the third request gets the value 3.