0
0
Node.jsframework~5 mins

Creating a basic HTTP server in Node.js - Quick Revision & Summary

Choose your learning style9 modes available
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?
Ahttp
Bfs
Cpath
Durl
What method do you use to start listening for incoming requests?
Aserver.start()
Bhttp.createServer()
Cserver.listen()
Dhttp.listen()
In the server callback, which object contains information about the client's request?
Aserver
Brequest
Cresponse
Dclient
How do you send a response header with status 200 and content type 'text/plain'?
Aresponse.writeHead(200, {'Content-Type': 'text/plain'})
Bresponse.write('200', 'text/plain')
Cresponse.setHeader(200, 'text/plain')
Dresponse.sendHeader(200, 'text/plain')
What happens if you forget to call response.end()?
AThe server crashes
BThe server restarts
CThe response is sent automatically
DThe client keeps waiting and connection stays open
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.