When we order chicken, we say ‘it is A apartment in B area, … please deliver us a chicken’ then we get a chicken after some time in the right place where we talked.
In this situation, putting URL on web browser is ordering chicken and getting the web page from the web server is getting the chicken from the restaurant. It’s the basic understanding about request and response
Depending on the way to send the ordering, we can call the server as HTTP
web server or HTTPS
web server etc.
When we use request
message, we get proper web page for users.
When we use response
message, we can save and take cookies
and force to move the page.
In http module, the most important object is server
. we can declare server
by using createServer()
method.
Server object’s method
1 | listen(port[, callback]) — Start server |
Server object’s event
1 | request — when client asks something |
When we want to provide an web page, we need to write response message. And at that time, we use response object which is the 2nd parameter from request event listener.
Response object’s method
1 | writeHead(statusCode[, statusMessage][, headers]) — write down the response header |