Skip to content

Deploying

Set environment variables for staging and live

Add API keys, database URLs and other settings as environment variables on DployHub, separately for staging and live, and apply them with a redeploy.

Updated 3 min read

Environment variables are how you give your app settings and secrets without putting them in your code: database URLs, API keys, feature flags and so on. On DployHub every app has two environments, staging and live, and each one has its own set of variables. That lets staging talk to a test database while live talks to the real one.

Add or edit variables

  1. 1

    Open the app

    Go to Apps and open the app you want to configure.

  2. 2

    Open the Environment variables tab

    Choose staging or live at the top of the tab. Each environment keeps its own list.

  3. 3

    Add a name and a value

    For example DATABASE_URL and the connection string your app should use. Add as many as you need.

  4. 4

    Save

    Your variables are stored encrypted. Existing values are shown masked as •••••• until you click Reveal.

  5. 5

    Redeploy or restart

    Saved changes apply the next time the environment starts. Click Restart to pick them up with the current version, or deploy a new version.

Naming rules

  • Names can use letters, numbers and underscores, and cannot start with a number. STRIPE_KEY and API_V2_URL are fine; 2FA_SECRET and my-key are not.
  • Names can be up to 128 characters long.
  • Values cannot contain line breaks. A value with a line break is skipped and you see a warning. If you need a multi-line value such as a private key, store it base64-encoded and decode it in your app.

Reading variables in your app

Variables reach your app as normal process environment variables, so you read them the same way you would on your laptop.

js
// Node.js
const dbUrl = process.env.DATABASE_URL;
const port = process.env.PORT || 3000;
python
# Python
import os

db_url = os.environ["DATABASE_URL"]
debug = os.environ.get("DEBUG", "false") == "true"

For static sites built with tools like Vite or Create React App, variables are baked in at build time, not read at runtime. Use the prefix your tool expects (for example VITE_ or REACT_APP_) and redeploy so the build picks them up. Because Go live promotes the staging build without rebuilding, live serves whatever values were baked in on staging — keep build-time variables identical in both environments. Never put secrets in a front-end build, because anyone can read them in the browser.

The PORT variable

We set PORT automatically to the port in your app settings, unless you set it yourself. Your app should listen on process.env.PORT (or os.environ["PORT"]) and on 0.0.0.0. See Port and health checks for details.

Copy from staging to live

When staging is working and you are ready to go live, the live tab has a Copy from staging button. It copies staging variables into live so you do not have to retype them. Review the copied values afterwards: you usually want live to point at production services, not test ones. Then restart live or go live with a new version.

Frequently asked questions

Why did my new variable not show up in the app?

Changes apply on the next start. Restart the environment or deploy again after saving.

Are my secrets stored safely?

Yes. Values are encrypted at rest and shown masked in the dashboard until you click Reveal.

Do staging and live share variables?

No. Each environment has its own list. Use Copy from staging to bring staging values into live.