How Do Frontend Developers Build Their First Backend API?
For Frontend developers learning backend development · Based on Traversy Media Node/Express REST API Builder
// TL;DR
If you're a frontend developer who knows JavaScript and React but has never built a backend, this skill bridges the gap. You'll create a CRUD REST API using Node.js and Express — no new language required. The workflow covers project setup with ES modules (the same import/export you use in React), route/controller separation, Postman testing for HTTP verbs browsers can't send, and in-memory data storage you can later swap for PostgreSQL. Use it when you want to stop mocking APIs and start building real ones.
Why is this Express pattern perfect for frontend developers?
You already know JavaScript — that's 80% of the battle. Node.js runs the same language on the server. Express is the backend equivalent of a lightweight router like React Router: you define paths and attach handler functions. The Traversy Media Node/Express REST API Builder uses ES module syntax (`import`/`export`), which is identical to what you write in React components.
The mental model shift is small: instead of handling user events and updating the DOM, you handle HTTP requests and return JSON responses. Instead of useState, you have a data array. Instead of onClick handlers, you have route handlers.
What backend concepts do frontend developers need to learn?
Three concepts matter most:
1. Middleware — Functions that run between receiving a request and sending a response. `bodyParser.json()` is middleware that parses the JSON body of POST/PATCH requests and attaches it to `req.body`. You register it with `app.use()` before your routes. Think of it like a React context provider that wraps your app.
2. req.params vs req.body — `req.params` holds dynamic URL segments (like React Router's useParams). If your route is `/:id`, then `req.params.id` gives you the value. `req.body` holds the JSON payload sent in POST/PATCH requests — similar to form data you'd manage with state.
3. HTTP methods beyond GET — As a frontend developer, you've used `fetch()` with GET, POST, PUT, and DELETE. On the backend, you define handlers for each method: `router.get()`, `router.post()`, `router.patch()`, `router.delete()`. The route path can be identical — the method differentiates them.
How do you structure an Express project coming from React?
React apps have components in /components and pages in /pages. Express APIs have handlers in /controllers and route definitions in /routes. The mapping is intuitive:
| React | Express |
|-------|----------|
| /components | /controllers |
| /pages (or routes) | /routes |
| App.js (mounts pages) | index.js (mounts routes) |
| useState | let dataArray = [] |
| useParams() | req.params |
| form state | req.body |
Create /routes/users.js with `express.Router()` — it defines five paths with their HTTP verbs. Create /controllers/users.js — it exports five functions containing all logic. In index.js, mount the router: `app.use('/users', usersRoutes)`. This is like wrapping a route group under a path prefix in React Router.
How do you test endpoints you can't hit from a browser?
As a frontend developer, you're used to typing URLs in the browser. That only sends GET requests. For POST, PATCH, and DELETE, you need Postman.
Open Postman, set the HTTP method to POST, enter `http://localhost:5000/users`, click Body → raw → JSON, and type your JSON payload. Click Send. You'll see the response from your controller's `res.send()` call. This is the backend equivalent of testing a component in Storybook — you're isolating and verifying each operation.
Common Postman mistake: forgetting to set the body type to 'raw' and format to 'JSON'. Without this, the server receives an empty body.
What should you build after your first API?
Connect your API to a React frontend. In your React app, use `fetch()` or Axios to call `http://localhost:5000/users` for GET requests, send JSON bodies for POST and PATCH, and send DELETE requests by ID. You'll finally understand both sides of the API contract.
Then swap the in-memory array for PostgreSQL. Install the `pg` package, replace array operations in your controllers with SQL queries, and your routes remain untouched. This is the power of separation — your React frontend doesn't change either because the API contract (URLs, methods, JSON shapes) stays the same.
Start now: create a new folder, run `npm init -y`, and follow the 12-step workflow. You'll have a working API before your next coffee refill.
// FREQUENTLY ASKED QUESTIONS
Do I need to learn a new language to build a backend API?
No. Node.js runs JavaScript on the server, so you use the same language you already know from frontend development. Express uses familiar concepts: import/export syntax, arrow functions, array methods like find() and filter(). The Traversy Media pattern even uses ES modules, which is the same import/export style used in React.
How is Express routing different from React Router?
React Router matches URL paths to components that render UI. Express routing matches URL paths plus HTTP methods (GET, POST, PATCH, DELETE) to handler functions that return JSON data. Express also uses express.Router() to group routes in separate files, similar to how React Router nests route definitions. The path-matching concept is essentially the same.
Can I connect this Express API to my React frontend?
Yes. Run the Express API on port 5000 and your React app on port 3000. In React, use fetch() to call http://localhost:5000/users for GET requests, and send JSON bodies for POST and PATCH. You may need to add CORS middleware (npm install cors, then app.use(cors())) in your Express app to allow cross-origin requests from port 3000.