After this lesson, you will be able to: Understand how a backend server works and build a simple HTTP API in Node.js using Express that responds to requests.
Up to now, everything you've built runs in the browser. The backend is the other half: code that runs on a server, talks to a database, and serves data to your frontend. This lesson covers what a backend is, why it exists, and walks through a tiny Node.js + Express API you can run in your editor.
Anything that has to be private, shared between users, or hidden from view has to live on a server, not in the browser. Examples: storing user accounts, talking to a payment API with secret keys, or making sure two users see the same up-to-date data. A backend is just a program that listens for HTTP requests and returns responses. JSON data, HTML, or files.
Diagram coming soon!
Three-tier diagram. Browser (frontend) ↔ Backend Server (Node + Express) ↔ Database (PostgreSQL), with arrows labeled Request, Response, SQL
Node.js is a runtime that lets you run JavaScript on a server. It comes with npm, the package manager you'll use to install thousands of open-source libraries. Everything you've learned about JavaScript still applies, but on the server, you also get access to the file system, the network, and (with libraries) databases.
Express is the most common Node.js framework for building APIs. It takes about 10 lines to get a server running.
// server.jsconst express = require("express");const app = express();app.use(express.json());app.get("/", (req, res) => {res.send("Hello from the backend!");});app.get("/api/greet", (req, res) => {const name = req.query.name || "friend";res.json({ message: `Hello, ${name}!` });});app.listen(3000, () => {console.log("Server running on http://localhost:3000");});
POST routes accept data in the request body. Combined with express.json(), you can build full APIs.
const messages = [];app.get("/api/messages", (req, res) => {res.json(messages);});app.post("/api/messages", (req, res) => {const { text } = req.body;if (!text) return res.status(400).json({ error: "text required" });messages.push({ text, createdAt: Date.now() });res.status(201).json({ ok: true });});
Use the in-browser editor, no local setup required.
Create a new "Node.js" repl in your editor
In the Shell tab, run npm install express
Paste the Hello World code into index.js (or server.js)
Click Run. your editor will show a URL where your server is reachable
Visit /api/greet?name=Alex in your browser, you should see JSON
Hint: think about what "secret" means.
Sign in and purchase access to unlock this lesson.