Lesson 16: Connecting It All: A Full-Stack App, Step by Step
You now know the pieces of a full-stack application: a browser that shows pages, a server that answers requests, an API that serves data, and a database that stores it. This lesson puts them together into one working application, a small course catalogue, and walks through the whole journey of a single feature, from a visitor typing a search to the answer appearing on screen. Seeing the whole chain in one place is the point of this lesson: each part is simple on its own, and the skill of full-stack development is knowing how they fit, where each job belongs, and what to check when something goes wrong.
The shape of the application
Our worked example is a course catalogue with three parts. The frontend is a single HTML page with a search box and a list, styled with CSS, and a small JavaScript file that handles the search. The backend is an Express server with two routes: GET /api/courses, which returns all courses, and GET /api/courses/:id, which returns one. The database is a single table called courses, with columns for id, title, description and lesson count, holding one row per course. The parts talk to each other only through the API: the frontend never touches the database, and the database never knows about the browser, which means each part can be changed or replaced without breaking the others, as long as the API stays the same.
One search, end to end
Follow a search for “French” through the system. The visitor types in the box and submits the form, and JavaScript prevents the reload, reads the value, and calls fetch('/api/courses?search=French'). The server receives a GET request, reads the search value from the query string, and asks the database with a parameterised query: SELECT * FROM courses WHERE title LIKE ?, with the value wrapped in percent signs so it matches any title containing the word. The database returns the matching rows, the server sends them back as JSON, and the frontend builds a list item for each one with createElement and appends it to the page. If nothing matches, the frontend says so plainly, and if the request fails, it says the search is unavailable and offers a link to browse all courses. Every step is one you have already practised, and the chain is only as strong as its weakest link, so each step checks its input and handles its errors.
Where each job belongs
A common beginner mistake is to put every job in the wrong place, so it is worth stating the division clearly. The browser's jobs are to show the interface, collect input, and display results, and it should never be trusted with secrets or with decisions that matter, because anyone can open the console and change what runs there. The server's jobs are to check input, enforce the rules, talk to the database, and keep secrets such as passwords and API keys, which live in environment variables on the server, never in frontend code. The database's jobs are to store data safely, enforce its own rules, such as unique ids, and answer questions quickly. When you are unsure where a piece of logic belongs, ask who should be allowed to change it: if the answer is “only the server”, it belongs on the server.
Testing the whole chain
Test a full-stack feature in layers, from the inside out. First, test the database query on its own and check it returns the right rows. Then test the API route with a tool such as curl or Postman, checking both a good request and a bad one, and read the status code and the JSON that comes back. Then test the frontend in the browser, watching the network tab to see the request go out and the response come in, and the console for errors. If something breaks, the layer where the data stops flowing tells you where the bug lives: no request in the network tab means the frontend never sent it, a 404 means the route is wrong, a 500 means the server code failed, and an empty response means the query found nothing. Work through the chain one link at a time, and the bug will show itself.
Watch & Learn
One video to watch for this unit, from a trusted educator.
- Node.js and Express.js - Full Course — freeCodeCamp.org
John Smilga builds Node and Express servers from scratch, including HTTP, routing, JSON APIs and middleware — the backend side of this unit, step by step.
Key Terms
- Full-stack
- Working across the whole application: frontend, backend, API and database.
- Frontend
- The part of an application that runs in the browser: pages, styles and interaction.
- Backend
- The part that runs on the server: routes, rules, and talking to the database.
- Query string
- The part of a URL after a question mark, such as ?search=French, carrying extra information.
- Environment variable
- A setting stored on the server, such as a secret key, read by code but never sent to the browser.
- End to end
- Following a feature through every layer, from the visitor's action to the answer on screen.
Discussion Questions
- Why should the frontend never be trusted with a decision that matters, such as whether a visitor may see a page?
- A search returns no results even though the course exists. Which layer would you check first, and how would you narrow it down?
- Why is it valuable that the frontend and the database only talk through the API?
Practice Questions
- In the worked example, which part of the application talks to the database?
- What does the query string in /api/courses?search=French carry?
- Where should a secret key be kept, and why?
- The network tab shows no request when the visitor searches. Where is the bug?
- Why should each layer check its input and handle its errors?
Show answers
- Only the backend server. The frontend asks the API, and the API asks the database, so the database is never exposed to the browser.
- The search value, French. The server reads it from the request and uses it to filter the courses it returns.
- In an environment variable on the server. Frontend code is visible to anyone, so a secret in the frontend is not a secret at all.
- In the frontend JavaScript. The request never left the browser, so the problem is before the server is involved.
- Because a chain is only as strong as its weakest link. If one layer passes bad data on silently, the failure shows up somewhere else and is much harder to find.