Skip to main content
Technical Enough
Next: Frontend

Environments: why it works on your machine and breaks online

Chapter 7 of 7 in The Software Map · 16 min · the part’s closing chapter

Last night the running-club site worked fully on your laptop. Tonight you asked the agent to put the site on the internet, got back a link ending in vercel.app, and sent it to the club. The first reply is a screenshot: a member pasted a message into the tidy page and got the host's gray Application error page instead of a clean post. You check git, and not one line of code has changed since the version that worked. The one value the tidy page needs still sits in a file on your laptop, and the host was never given it.

Engineers have a name for this moment: it works on my machine, the oldest complaint in software. The code is the same in both places, but something around the code is different.

Find the problem in the host's log

The error page is written for visitors and says almost nothing. A log is the running list of lines a program writes while it works, and every host shows it on a tab with that name. Near the moment the member opened the page, two lines show the problem:

Error: MODEL_API_KEY is not set
    at tidy (app/api/tidy/route.js:4)

The first line says the program looked for a value called MODEL_API_KEY and found none. The second says where: line 4 of app/api/tidy/route.js, the file behind the tidy page's endpoint. That value is the API key from The journey of a request.

An environment variable is a value a program reads when it starts, from the place it runs rather than from its own code, like a sticky note it checks at startup. The .env file is the locked drawer from the plan, a small text file of those values that stays on your laptop. The agent wrote MODEL_API_KEY into it when it set up the tidy page, so the page worked at home. The host has a settings screen for the same values, called Environment Variables, and its row for MODEL_API_KEY stays empty until you fill it.

The key stayed home because of a second small file. The file .gitignore is a short list of files git must never save, a do-not-pack list, and .env is on it. The host received only the files git had saved, so the code traveled and the secret stayed home.

The fix takes five minutes

To deploy is to move code from where it runs now to where users can reach it, the way a recipe moves from your kitchen to a restaurant's. Paste the value into the empty row on the host, then ask the agent to deploy again. A build is the runnable version the host makes from your files before it starts the site, and it makes a new one on every deploy. This time the key is in place when the build starts, the log shows no error, and the club's link shows a clean post.

Deploy means moving code from where it runs now to where users can reach it. The code goes to the new place, but the settings around it do not, so you set them again there.

What was actually different

One value existed on your laptop and not on the host, and that was enough to break a page. The setup around your code includes many details like that one. An environment is everything around the code, the kitchen around the recipe. When code works in one place and fails in another, the other machine is rarely broken; the two kitchens differ in a detail you have not found yet.

An environment is everything around the code: the machine, the installed tools, the settings, and the data. The same code in two environments can behave like two different apps.

The three environments most teams run

You eventually meet these differences on every project, so teams give standard names to the places where code runs. The Environment Variables screen is already built around the three names below: beside each value, the host asks which copies of the site can use it.

  • Development (dev for short) is your own machine, where breaking things is cheap and private. The site has run there since the morning you first started it.
  • Preview is a private copy the host makes for each change, a dress rehearsal before anyone outside sees it. Teams once built this copy by hand and called it staging.
  • Production is the real thing, the version your users actually see and use; think of it as opening night.

A change starts on your machine because there it can fail with no audience. Next it goes to the preview copy, which runs in the host's kitchen, so a difference your laptop could not show you, like a missing key, appears there. Only then does the change go to production.

The drawing shows the three environments as zones, with a gate between each zone and the next: a change waits at each gate until someone checks that it worked, and only then moves on. You do not build the preview zone yourself: every time the agent pushes a change to GitHub, the host makes a preview copy for free and shows you a private link. If your change had gone through preview first, the missing key would have broken the preview copy in front of you, not the site the club uses.

The obvious objection: this is too much process for one person with one laptop

Gates sound like process built for companies, so shipping straight from the laptop to the live site is tempting. But you already run two of the three environments: your laptop has been development since the site first ran there, and the link you sent the club is production. The host makes the third for free with every push, so the only extra step is opening the preview link before anyone else sees the change. Choosing and paying for the host is a topic for Hosting, renting a computer on the internet, later in the course.

What happens when a change goes to everyone at once

On July 19, 2024, the security company CrowdStrike sent a faulty update to software running deep inside Windows machines worldwide. About 8.5 million machines crashed, flights were grounded, and payment systems stopped. The update went to every machine at once. In its review afterward, CrowdStrike committed to sending updates to a few machines first, watching them, and only then sending the update more widely. Watching those first machines is the subject of Monitoring, how you know it broke (and what it costs).

The cost of a bad change grows with the number of people who get it, so a change goes to your machine, then a preview copy, then the live site.

What you can do now that the map is complete

You can now understand the plan an agent prints and say where each part of a website or app runs, using the local and remote split from Where software lives. When a site works at home and breaks online, you can read the log to find the value that exists in one place and not the other.

Try it now

This drill takes about fifteen minutes. It costs nothing on the first path and a few cents of usage on the second.

No setup: Open the AI chat you already use and paste: "A site works on my laptop but fails online. The host's log says: Error: MODEL_API_KEY is not set. What is that value, where does it live on my laptop, and where do I set it on the host?" Check the answer against the two key ideas above, the one on deploy and the one on what an environment is.

With your tools: You arrive with the idea file and a first save point in the running-club folder. In Claude Code, the AI coding tool we use in this course, type: "Deploy this project to Vercel and show me the host's log." After you sign in to Vercel, it prints a link ending in vercel.app. If the tidy page there shows the Application error page, type: "Read the host's log and walk me through adding the missing environment variable on Vercel." Paste the value from .env into the empty row, deploy again, and the page works. Then ask the agent for any small change, and before you let that change go to production, open the private preview link the host shows for that push. Codex and Cursor, two other coding tools, accept the same requests in their chat panels. If nothing is installed yet, The Setup Clinic covers the install.

Either way, finish by organizing the idea file. It now has one line from each chapter; add this header, a title and five labeled lines, above those lines:

What I approved and why
Idea:     a running-club site with trails, RSVPs, and a tidy page
Approved: host Vercel; JavaScript with Next.js;
          the AI step runs on the server
Rule:     save point before every agent session
Secret:   MODEL_API_KEY, in .env on my laptop,
          in Environment Variables on Vercel
Words:    environment, deploy, log, preview, production

In later chapters you add lines beneath that header.

Chapter Summary

  • The site broke online because one environment variable, MODEL_API_KEY, existed in the .env file on your laptop and not on the host; the host's log named it.
  • Deploy means moving code from where it runs now to where users can reach it; the code goes to the new place, but the settings around it do not, so you set them again there.
  • The .env file stays on your laptop because .gitignore lists it as a file git must never save, and that is the right place for a secret.
  • An environment is everything around the code: the machine, the installed tools, the settings, and the data. The same code in two environments can behave like two different apps.
  • Most teams run three environments: development on your own machine, preview as a private copy the host makes for each change, and production where your users are.
  • A change moves from development to preview to production, and it moves to the next environment only after it worked in the one before; the host makes the preview copy for free on every push.
  • The cost of a bad change grows with the number of people who get it: in July 2024 a faulty CrowdStrike update went to every machine at once, and about 8.5 million machines crashed.
  • When an agent says a change is tested, ask where it ran before you trust it.
  • Your artifact is the idea file, now with its header "What I approved and why" above the line from each chapter.
  • Next comes the part called The Technology Stack, which begins with Frontend, what users see, the layer of the site your members actually see.

Sources

  • CrowdStrike post-incident review of the July 19, 2024 content update (last verified July 2026).
  • Public news reporting on the July 19, 2024 global IT outage (last verified July 2026).
  • Vercel documentation on environment variables and preview deployments (last verified July 2026).
  • Netlify documentation on deploy previews (last verified July 2026).
  • Git documentation on gitignore, git-scm.com (last verified July 2026).