Express.js Mastery / Introduction To Back-End Web Development

An Overview of How the Web Works

🌐 The Core Concept: Request-Response Model

  • πŸ’» Your browser (client) sends a request to a server.

  • πŸ—„οΈ The server sends back a response with the requested page or data.

  • πŸ”„ This back-and-forth is called the request-response model or client-server architecture.


πŸ›£οΈ Step-by-Step: What Happens When You Type a URL

🌐 Example URL

<https://google.com/maps>

🧩 Breaking Down the URL

Example: https://google.com/maps

πŸ“Œ Part

πŸ“ Example

πŸ’‘ Meaning

πŸ”’ Protocol

https://

The protocol used for the connection (HTTP or HTTPS)

🌍 Domain name

google.com

A human-friendly name for the server

πŸ“‚ Resource path

/maps

The specific resource being requested on that server


🌐 Step 1: DNS Lookup (Domain Name β†’ IP Address)

❓ The Problem

  • A domain name like google.com is easy for people to remember, but computers can't use it directly.

  • To connect to a website, a computer needs the website's IP address.

πŸ’‘ The Solution: DNS

  • DNS (Domain Name System) works like the phone book of the internet. It converts domain names into IP addresses.

πŸ”„ How It Works

  1. 🌐 You enter google.com in your browser.

  2. πŸ” The browser asks a DNS server (usually provided by your ISP) for the IP address.

  3. πŸ“€ The DNS server returns the website's IP address.

  4. πŸš€ The browser uses that IP address to connect to the server.

🌍 The Actual Address Used

Once the IP address is found, the browser connects using: protocol://IP_address:port

πŸ”Œ What Is a Port?

  • A port identifies a specific service on a server.

  • Example: our Node.js server used port 8000.

  • The resource path (like /maps) is sent separately in the HTTP request.


🀝 Step 2: Establishing a Connection (TCP Socket)

  • 🌐 After getting the server's IP address, the browser creates a TCP connection with the server.

  • πŸ”Œ This connection stays open while the website's data is being transferred.

  • πŸ“¦ TCP (Transmission Control Protocol) ensures data is sent and received reliably.

  • 🌐 IP (Internet Protocol) helps data reach the correct destination.

  • πŸ“š Together, TCP/IP are the rules that allow devices to communicate over the internet.

πŸ’‘ A protocol is simply a set of rules for communication.


πŸ“¨ Step 3: Making the HTTP Request

Once connected, the browser sends an HTTP request with three parts:

  1. πŸ“ Start line β€” method (GET, POST, PUT/PATCH), path, HTTP version

  2. πŸ“‘ Headers β€” metadata (browser type, language, time, etc.)

  3. πŸ“¦ Body (optional) β€” data being sent, e.g. a form submission


πŸ”’ HTTP vs. HTTPS

  • πŸ” HTTPS is the same as HTTP, but encrypted using TLS or SSL (additional security protocols).

  • βœ… Aside from this encryption layer, the same request/response logic applies identically to both HTTP and HTTPS.


πŸ“¨ Step 4: The Server Responds (HTTP Response)

The server replies with a similarly structured message:

  1. πŸ“ Start line β€” HTTP version, status code (βœ… 200 OK, ❌ 404 Not Found), status message

  2. πŸ“‘ Headers β€” set by the backend developer

  3. πŸ“¦ Body β€” the actual content (HTML, JSON, etc.)


🌐 Step 5: Multiple Requests for a Single Website

  • πŸ“„ The first request retrieves the HTML.

  • πŸ” The browser scans the HTML for CSS, JavaScript, images, and fonts.

  • πŸ“¨ The browser requests each of these files separately.

  • ✨ Once all the files are downloaded, the browser renders the webpage.


🧐 How TCP/IP Actually Moves the Data

  • 🚚 TCP splits data into small packets and reassembles them at the destination β€” much faster than sending one giant chunk

  • 🧭 IP handles routing, making sure each packet reaches the right address


πŸ›£οΈ Full Journey, Summarized

  1. ⌨️ User types a URL.

  2. πŸ” DNS resolves the domain to an IP.

  3. πŸ”Œ Browser opens a TCP connection.

  4. πŸ“¨ Browser sends an HTTP request.

  5. πŸ“€ Server sends back an HTTP response.

  6. πŸ“„ Browser requests additional assets (CSS/JS/images).

  7. ✨ Browser renders the final page.

  8. 🌍 TCP/IP handles packet transfer underneath it all.