Recall & Review
beginner
What Node.js module is used to create a basic HTTP server?
The
http module is used to create a basic HTTP server in Node.js.Click to reveal answer
beginner
What method starts the server and listens for requests?
The
server.listen(port, callback) method starts the server and listens on the specified port.Click to reveal answer
beginner
In the callback for
http.createServer(), what are the two main objects provided?The callback receives
request and response objects. request contains info about the incoming request, and response is used to send data back to the client.Click to reveal answer
beginner
How do you send a plain text response 'Hello World' to the client?
Use
response.writeHead(200, {'Content-Type': 'text/plain'}) to set status and headers, then response.end('Hello World') to send the response and close the connection.Click to reveal answer
beginner
Why is it important to call
response.end() in a Node.js HTTP server?Calling
response.end() signals that the response is complete. Without it, the client will keep waiting and the connection stays open.Click to reveal answer
Which Node.js module do you import to create an HTTP server?
✗ Incorrect
The
http module provides the tools to create an HTTP server.What method do you use to start listening for incoming requests?
✗ Incorrect
The
listen() method starts the server and listens on a specified port.In the server callback, which object contains information about the client's request?
✗ Incorrect
The
request object holds details about the incoming client request.How do you send a response header with status 200 and content type 'text/plain'?
✗ Incorrect
Use
writeHead to set status and headers before sending the response body.What happens if you forget to call
response.end()?✗ Incorrect
Without
response.end(), the server does not finish the response, so the client waits indefinitely.Explain how to create a basic HTTP server in Node.js that responds with 'Hello World'.
Think about the steps from importing to sending a response and listening on a port.
You got /5 concepts.
Describe the roles of the request and response objects in a Node.js HTTP server.
Consider what each object lets you do during a client-server interaction.
You got /3 concepts.