Course outline · 0% complete

0/29 lessons0%

Course overview →

What a Backend Is

lesson 1-1 · ~9 min · 1/29

Two halves of every app

When you open a website, two programs cooperate.

  • The frontend is the code running in your browser: the buttons, text, and colors you see.
  • The backend is a program running on another computer, called a server, somewhere else in the world. It stores the data, checks passwords, and decides what each user is allowed to do.

The browser is called the client because it asks for things. The server answers. Every interaction follows the same cycle:

  1. The client sends a request: "give me the profile page for user 42".
  2. The server runs some code: look up user 42, check permissions.
  3. The server sends back a response: the data, plus a code saying how it went.

This course teaches you to write the program in the middle, using Node.js, a way to run JavaScript outside the browser.

Clientbrowser or appasks for thingsServeryour Node.js codeanswersrequest: GET /users/42response: 200 + data
The request and response cycle. A request travels from the client to the server, your code runs, and a response travels back.

Quiz

You type your password into a login form and press Submit. Which part of the app checks whether the password is correct?

A server is just a function

Strip away the network for a second. A backend is a function that takes a request and returns a response.

  • A request has a method (like GET, meaning "read something"), a path (like /hello), and sometimes data.
  • A response has a status code (a number: 200 means OK, 404 means not found) and a body (the content).

You can write that function in plain JavaScript right now, no server needed. Run the example below. The handle function is the entire idea of a backend in ten lines.

Code exercise · javascript

Run this tiny pretend server. handle takes a request object and returns a response object. Press Run and check that both lines print.

Code exercise · javascript

Your turn. Add a second route: when the path is "/about", return status 200 with body "About us". Keep /hello and the 404 fallback working.