Chapter 6. The Request and Response Objects

When you’re building a web server with Express, most of what you’ll be doing starts with a request object and ends with a response object. These two objects originate in Node and are extended by Express. Before we delve into what these objects offer us, let’s establish a little background on how a client (a browser, usually) requests a page from a server, and how that page is returned.

The Parts of a URL

Parts of a URL
Protocol
The protocol determines how the request will be transmitted. We will be dealing exclusively with http and https. Other common protocols include file and ftp.
Host
The host identifies the server. Servers on your computer (localhost) or a local network may simply be one word, or it may be a numeric IP address. On the Internet, the host will end in a top-level domain (TLD) like .com or .net. Additionally, there may be subdomains, which prefix the hostname. www is a very common subdomain, though it can be anything. Subdomains are optional.
Port
Each server has a collection of numbered ports. Some port numbers are “special,” like 80 and 443. If you omit the port, port 80 is assumed for HTTP and 443 for HTTPS. In general, if you aren’t using port 80 or 443, you should use a port number greater than 1023.[6] It’s very common to use easy-to-remember port numbers like 3000, 8080, and 8088.
Path
The path is generally the first part ...

Get Web Development with Node and Express now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.