StoicBuilder

HandbookII the ForumEnvironment variables

IIthe Forum, The shape of an app

Environment variables

1 min readUpdated 28 November

In plain words

A setting your app reads from outside the code, so secrets and per-machine values don't live in your files.

Where you see it

The "Environment variables" screen in Lovable or Vercel, or a .env file with lines like SUPABASE_URL=... Your code only says the name; the host fills in the value when the app starts.

app/api/checkout/route.tsserver
// runs on the server, never in the browserimport Stripe from "stripe"; const stripe = new Stripe( process.env.STRIPE_SECRET_KEY!);
The value lives on the host. The code only says its name.

What goes wrong

  1. Pasting the API key straight into the code, then pushing it to GitHub

    Bots scan public repos for keys within minutes. Once pushed, treat the key as leaked and replace it.

    const stripe = new Stripe("sk_live_51H...")
  2. Using a secret key in browser code

    Anything starting with NEXT_PUBLIC_ or VITE_ is shipped to every visitor's browser, where anyone can read it.

    VITE_STRIPE_SECRET_KEY=sk_live_...
  3. Forgetting to add the variable on the host

    It works on your laptop, where the .env file lives, then breaks after deploy because the host never got the value.

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Move every API key into environment variables. Keep secret keys server-side only, list the variables I need to set on my host, and never print their values.

Quick check

Sign in to earn +10 XP for it

Your app works on your laptop but payments break after deploy. Most likely?

Got a prompt that touches environment variables?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.