web development / backend
Learn Backend Development for Free: Build and Test a REST API Step by Step
Backend learning stalls when it stays abstract. This guide follows one HTTP request from the browser to the database, shows which status code to return and why, and gives you a small Express 5 API with passing tests you can run today.
Most backend roadmaps are a list of nouns: servers, APIs, databases, authentication, caching, queues. A list does not tell you what to build first or how to know it works. The way through is to pick one request, such as "save a note," and trace it end to end. Every backend concept you meet later is a refinement of one step on that route.
The language matters less than people argue about. This page uses JavaScript with Node.js and Express because the free resources are strong and you can reuse the language on the frontend. The same route-handler-database pattern applies in Python, Go, Java or C#, so treat the code as a model and not a requirement.
01 · THE ROUTE OF A REQUEST
What happens between a browser click and your database
| Step | What happens | What to learn |
|---|---|---|
| 1. Request | The client sends a method, a path, headers and sometimes a JSON body | HTTP methods, headers, JSON |
| 2. Routing | The server picks the function that handles that method and path | Routes and parameters |
| 3. Validation | The handler checks the input before using it | Never trust the client |
| 4. Logic and data | The handler reads or writes the database | SQL, transactions, indexes |
| 5. Response | The server returns a status code, headers and a body | Status codes, error shapes |
| 6. Cross-origin check | A browser on another origin only reads the response if the headers allow it | CORS |
Steps 3 and 5 are where beginner code goes wrong. Validation is skipped, and every outcome returns 200. The rest of this guide spends its time there, because these habits separate an API a frontend can rely on from one that works only for the person who wrote it.
02 · STATUS CODES
Which status code to return
A status code is the first thing a client reads. The full list lives on MDN, but a handful cover nearly every case in a CRUD API.
| Situation | Return | Why |
|---|---|---|
| Read succeeded | 200 | The default for a successful GET |
| Created a new record | 201 | Tells the client something new exists; add a Location header |
| Body missing or invalid | 400 | The client sent something your handler cannot use |
| Not logged in | 401 | No valid credentials were supplied |
| Logged in but not allowed | 403 | Credentials are fine; permission is not |
| Record does not exist | 404 | The path is valid but nothing is there |
| Your code threw | 500 | A server fault, not the client's fault |
200 {"ok": false} hides every failure from them.03 · A WORKING API
A notes API with tests, in about 50 lines
This API stores notes in memory, which is deliberate: it lets you learn routing, validation and status codes before adding a database. It was run on Express 5.3.0 and Node 22. Install with npm install express, save the file as app.mjs, and note that the .mjs extension enables ES module imports.
import express from 'express';
const app = express();
app.use(express.json());
const notes = [];
let nextId = 1;
app.get('/notes', (req, res) => res.json(notes));
app.post('/notes', (req, res) => {
const text = req.body?.text;
if (typeof text !== 'string' || text.trim() === '') {
return res.status(400).json({ error: 'text is required' });
}
const note = { id: nextId++, text: text.trim() };
notes.push(note);
res.status(201).location(`/notes/${note.id}`).json(note);
});
app.get('/notes/:id', (req, res) => {
const note = notes.find((n) => n.id === Number(req.params.id));
if (!note) return res.status(404).json({ error: 'not found' });
res.json(note);
});
export default app;The tests use the test runner built into Node.js, so there is nothing else to install. Save this next to the app and run node --test. It starts the server on a random free port, which avoids clashes with anything already running.
import test from 'node:test';
import assert from 'node:assert/strict';
import app from './app.mjs';
const server = app.listen(0);
const base = `http://localhost:${server.address().port}`;
test.after(() => server.close());
const post = (body) =>
fetch(`${base}/notes`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify(body),
});
test('creates a note and returns 201', async () => {
const res = await post({ text: 'learn status codes' });
assert.equal(res.status, 201);
assert.equal((await res.json()).text, 'learn status codes');
});
test('rejects a missing text field with 400', async () => {
assert.equal((await post({})).status, 400);
});
test('returns 404 for an unknown id', async () => {
assert.equal((await fetch(`${base}/notes/999`)).status, 404);
});Three tests pass: a valid note returns 201, a body without text returns 400 and an unknown id returns 404. Add a fourth test for a whitespace-only string before moving on, because that is the case most validation misses.
npm audit and updating packages.04 · DATA
Add a database after the API behaves
Swap the in-memory array for a database once your tests pass, so you can tell whether a new bug comes from the database or the handlers. For a first project, a relational database with SQL is the safest choice, because the concepts of tables, keys, joins and transactions carry to almost every backend job. PostgreSQL has an official tutorial in its documentation, and SQLBolt teaches the query language in the browser with no setup.
Learn plain SQL before an ORM. An ORM hides queries until the day one is slow, and then you need to read it. Once you can write a join and explain an index, an ORM becomes a convenience rather than a mystery.
05 · AUTHENTICATION
Use the checklists, not your own scheme
Login is the part of a backend most likely to hurt someone if it is wrong. Do not design your own scheme. OWASP maintains cheat sheets with specific, current guidance on authentication and on how to store passwords, and the OWASP Top 10 lists the most critical web application risks. Read the password storage sheet before you store a single password, and prefer a well-maintained library or a hosted identity service over code you write yourself.
06 · FREE RESOURCES
Where to learn it, in a sensible order
- MDN: server-side first steps ↗A framework-neutral explanation of what a server does with a request.developer.mozilla.org
- MDN: Express web framework tutorial ↗A module with a full Local Library tutorial covering routes, templates, forms, a database and deployment.developer.mozilla.org
- MDN: HTTP response status codes ↗The reference behind the table above.developer.mozilla.org
- MDN: CORS ↗Why a browser blocks a response, and the headers that fix it.developer.mozilla.org
- Express: routing guide ↗The official routing documentation.expressjs.com
- Node.js test runner ↗Documentation for the built-in node:test module used above.nodejs.org
- The Odin Project: NodeJS ↗A free project-based course on Express, databases and authentication.theodinproject.com
- PostgreSQL tutorial ↗The official getting-started tutorial from the documentation.postgresql.org
- SQLBolt ↗Interactive SQL lessons in the browser.sqlbolt.com
- OWASP: password storage ↗Current guidance on storing passwords safely.cheatsheetseries.owasp.org
- OWASP: authentication ↗A checklist for building login correctly.cheatsheetseries.owasp.org
- roadmap.sh backend roadmap ↗A visual map of topics to come back to after the first project.roadmap.sh
07 · FAQ
Frequently asked questions
Which language should I learn for backend development?
Pick one that has strong free learning resources and that you will keep using. JavaScript with Node.js is a common first choice because the same language runs on the frontend. Python, Go, Java and C# all use the same ideas of routes, handlers and databases.
Do I need to learn frontend before backend?
No. You can build a backend alone and test it with automated tests or a tool that sends HTTP requests. You do need to understand HTTP and JSON, which are the contract between the two sides.
What should I build first?
A small REST API with create, read and a not-found case, tested with automated tests. Add a database only after it behaves, then add login. This keeps each new problem separate.
Should I learn SQL or a NoSQL database first?
Learn SQL first. Relational concepts such as tables, keys, joins and transactions apply widely, and PostgreSQL and SQLBolt both teach them for free. You can add a document or key-value store later for a specific need.
How long does it take to learn backend development?
A working REST API with a database is a realistic target for a few months of steady part-time study. Authentication, deployment and performance take longer, because they are learned by running into real problems.