Skip to Content
Configure an app

Environment variables

Set the variables your app reads, keep secrets hidden, and share one value with several apps.

API keys, database URLs, NODE_ENV. Set them on the app's Environment tab. The app gets them at build time and at run time.

Add variables

Open Environment

Open the app, then Environment, and click Add. A new row opens at the top.

One app's Environment tab with its variables, sources and secret values

Type the name and the value

Turn on Secret for a credential. To add many at once, paste a whole .env into the Key field: you get one row per line. Save in the bar at the bottom adds them all.

The Add environment variables dialog, key and value rows plus the Secret switch

Redeploy

Variables reach the app on the next deploy. Click Redeploy on the Changes not deployed yet notice.

The arrow next to Add also offers Database, to connect a managed database's connection string.

Plain and secret

PlainSecret
Shown againYesNever
EditYesNo: delete it and add it again
Change the typeTo secret, with Edit or Make Secret on selected rowsNever back to plain

A plain variable named like a credential, such as DB_PASSWORD, gets a warning icon.

Share a variable with several apps

One value, like a SENTRY_DSN, that several apps use. Change it once and every app gets it on its next deploy.

Create it

Variables in the sidebar, the Shared tab, then New shared variable. Secret applies to every row.

Every variable in the team on one page, shared ones included

Pick who it is offered to

ScopeOffered to
This teamEvery app in the team
ProjectsThe apps of the projects you pick, or only of some of their environments
Specific appsThe apps you pick. The only scope that adds it to them right away

Add it to the app

On the app's Environment tab, the arrow next to Add, then Shared. An offered variable reaches nothing until an app adds it. Then redeploy.

An app's Environment tab, where a linked shared variable shows its source

Remove from this app, on the row, drops it from this app only. Creating or changing a shared variable needs Manage environment variables on the whole team.

Which value wins

When one name is set in several places, the app gets the first of:

  1. A preview override, on a pull request preview only. They are in the Preview overrides section of the Environment tab.
  2. A shared variable the app has added.
  3. The app's own variable.

In a Compose app, a key the compose file sets itself keeps the compose value.

Good to know

  • A Dockerfile build sees only the names it declares with ARG, like ARG NEXT_PUBLIC_API_URL. Any other build gets every variable.
  • A .env.example in the repository lists its names at the top of the tab, with a warning icon, until you give each a value.
  • A preview built from a fork gets only the plain preview overrides.

Something wrong? See Deploys and builds.

Did this page help you?

On this page