Challenge - 5 Problems
Node.js HTTP Server Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this basic HTTP server response?
Consider this Node.js HTTP server code. What will the server send back to the client when accessed?
Node.js
import http from 'http'; const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader('Content-Type', 'text/plain'); res.end('Hello, world!'); }); server.listen(3000);
Attempts:
2 left
💡 Hint
Look at the content type and the string passed to res.end.
✗ Incorrect
The server sets the content type to 'text/plain' and sends the string 'Hello, world!' as the response body.
📝 Syntax
intermediate2:00remaining
Which option contains a syntax error in creating an HTTP server?
Identify the option that will cause a syntax error when creating a basic HTTP server in Node.js.
Attempts:
2 left
💡 Hint
Look for missing punctuation or misplaced code inside the callback.
✗ Incorrect
Option C is missing a semicolon or closing brace before calling server.listen, causing a syntax error.
❓ state_output
advanced2:00remaining
What is the value of 'count' after 3 client requests?
This server counts how many requests it has handled. What is the value of 'count' after 3 requests?
Node.js
import http from 'http'; let count = 0; const server = http.createServer((req, res) => { count++; res.end(`Request number: ${count}`); }); server.listen(3000);
Attempts:
2 left
💡 Hint
The count variable increases each time the server handles a request.
✗ Incorrect
Each request increments count by 1, so after 3 requests, count is 3.
🔧 Debug
advanced2:00remaining
Which option causes the server to crash on request?
One of these server codes will crash when a client makes a request. Identify which one.
Attempts:
2 left
💡 Hint
Check if the response is properly ended.
✗ Incorrect
Option A calls res.end twice, causing a 'write after end' error that crashes the server.
🧠 Conceptual
expert2:00remaining
What happens if server.listen is called twice on the same port?
Consider calling server.listen(3000) twice on the same HTTP server instance. What will happen?
Attempts:
2 left
💡 Hint
Ports can only be bound once per server instance.
✗ Incorrect
Calling listen twice on the same port causes an error because the port is already bound.