Skip to the workspace
Pebellslearn by building
Collaboration  ›  Lesson

React and Node.js

React 13 minReact builds the screen from components that run in the user's browser, while a Node.js server runs the code users must not read or change, such as secret keys, safety rules and limits.

ai product builder / React and Node.js

Explore each scene at your own pace.

01 · The rule

The rule

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.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.