← Dashboard

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.

updated Nov 2026·a 13-minute read·code run on Express 5.3 and Node 22

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

One request, step by step
StepWhat happensWhat to learn
1. RequestThe client sends a method, a path, headers and sometimes a JSON bodyHTTP methods, headers, JSON
2. RoutingThe server picks the function that handles that method and pathRoutes and parameters
3. ValidationThe handler checks the input before using itNever trust the client
4. Logic and dataThe handler reads or writes the databaseSQL, transactions, indexes
5. ResponseThe server returns a status code, headers and a bodyStatus codes, error shapes
6. Cross-origin checkA browser on another origin only reads the response if the headers allow itCORS

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.

Choosing a status code
SituationReturnWhy
Read succeeded200The default for a successful GET
Created a new record201Tells the client something new exists; add a Location header
Body missing or invalid400The client sent something your handler cannot use
Not logged in401No valid credentials were supplied
Logged in but not allowed403Credentials are fine; permission is not
Record does not exist404The path is valid but nothing is there
Your code threw500A server fault, not the client's fault
WATCHDo not return 200 with an error in the body. Frontend code, monitoring tools and caches all key off the status code. An API that answers 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.

app.mjsExpress 5
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.

app.test.mjsnode:test
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.

TIPKeep dependencies current. The Express homepage shows version 5.3.0, along with a security notice about a denial-of-service issue in its body-parsing middleware. After you finish the tutorial, make a habit of running 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

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.

Keep going

Backend connects to data, APIs, and deployment.