React and Node.js
Asha's builder wrote Pantry Pal with React for the screens and Node.js for the server. She does not need to master either. She needs one line she can draw with confidence: which code runs on the user's device, which runs on her server, and why her secrets and safety rules belong on one side of it.
The rule
React draws the screen; Node runs what users must not see or change.
React is a JavaScript library for building screens out of components: reusable pieces that take data and return what to show.
function DinnerCard({ title, minutes }) {
return (
<article className="card">
<h3>{title}</h3>
<p>{minutes} min</p>
</article>
);
}Pantry Pal shows one DinnerCard per suggestion. Change the component once and every card changes. In an app built like Pantry Pal, this code is sent to the user's browser and runs there, where anyone can read it. Some frameworks can also run React on the server first, but the rule holds: whatever reaches the browser is public.
Node.js runs JavaScript on a server: your machine, not theirs. Pantry Pal's server receives the item list, calls the model with a key kept in the server's own settings, removes allergens and sends back the dishes.
// Runs on the server. The browser never receives this value.
const key = process.env.MODEL_API_KEY;process.env reads environment variables: settings stored on the server, outside the code, so secrets never have to be written into files you share.
The two sides talk through requests. The React screen sends the pantry to a server address such as /api/suggest and waits for the reply. That address is the border between them, and the next lesson shows you how to watch every message that crosses it.
The shortcut
Could a user mess with it? For each piece of logic, ask whether it would be a problem if a user could read it or change it. Yes → server. No → it can live in the browser.
The model's secret key
If users can read it, someone else spends your money. Server.
Checks in the browser are still worth having for speed, such as "add at least one item" before sending anything. But they are conveniences. The server checks again.
Drills
Answer fast — trust the rule.
What is a React component?
In an app built like Pantry Pal, where does the DinnerCard component's code run?
What does process.env.MODEL_API_KEY do in the Node server?
The form checks "at least one item" in the browser. Does the server still need to check?
Remember
- React draws the screen; Node runs what users must not see or change.
- Ask "could a user mess with it?" Yes means server.
- Trap: secrets, safety rules or limits that live only in browser code.
