Skip to content

Environment variables

Real apps need configuration and secrets: API keys, database URLs, feature flags. In Factorly you add these as environment variables in the workspace, and they're injected wherever your code runs.

Adding a variable

In the workspace, open the environment variables panel and add a key/value pair, for example:

KeyValue
STRIPE_SECRET_KEYsk_live_…
OPENAI_API_KEYsk-…
NEXT_PUBLIC_APP_NAMEMy App

Your values are stored securely and are never hard-coded into your source — so they stay safe even when you export to GitHub.

Where they're available

Once set, your variables are injected into the three places your code actually runs:

  • the live preview (your running app),
  • the terminal,
  • and builds when you deploy.

Reading them in code

Read variables the standard way for your stack. In a Node / Next.js app:

// Server-side: full access to every variable.
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);

export async function createCheckout() {
  // ...
}

In frameworks that distinguish server and browser variables, follow that framework's convention. For example, Next.js only exposes variables prefixed with NEXT_PUBLIC_ to the browser:

// Safe to read in client components — it's a public value.
const appName = process.env.NEXT_PUBLIC_APP_NAME;

Never put a secret behind a public prefix. Keep keys like STRIPE_SECRET_KEY server-side only.

Tips

  • Just tell the agent: "I added OPENAI_API_KEY as an env var — use it for the summarize endpoint." It'll wire the code to read process.env.OPENAI_API_KEY.
  • If your app can't reach a service, double-check the variable name matches exactly what your code reads — env keys are case-sensitive.

Next: pick the right brain for the job in Choosing a model.