Node.js · Junior · Question 57 of 75
What does this code do?
import http from "node:http";
http
.createServer((req, res) => {
res.writeHead(200, { "Content-Type": "text/plain" });
res.end("Hello");
})
.listen(3000);- 1Sends one request to port 3000
- ✓Correct answer: Starts an HTTP server on port 3000 that answers every request with
Hello - 3Starts a server that only answers
GET /
Explanation
The callback runs for every request, whatever the method or URL. Routing by req.method and req.url is up to you, which is why frameworks like Express exist.