Environment variables
Settings and secrets your app reads at runtime, set per environment. Values are encrypted, and saving applies them to the running app.
Add and edit
Open Environment variables for your service. Add one at a time, or switch to the bulk editor to paste a whole .env file. Keys use capital letters, numbers and underscores, for example STRIPE_SECRET_KEY. Production and staging have their own sets.
What happens when you save
- Normal variables
- The app restarts with the new values, with no downtime.
- Build-time variables
- Keys starting
NEXT_PUBLIC_,VITE_,REACT_APP_,NUXT_PUBLIC_,PUBLIC_orEXPO_PUBLIC_are baked into the build, so the app is rebuilt. Your current version keeps running until the new one is live, and Deployment Center shows the result. - During a deploy
- Changes are saved and applied as soon as the running build finishes.
Reference another service
Instead of copying a value, point to it. References stay correct when the other value changes:
DATABASE_URL=${{Shop Database.DATABASE_URL}}
REDIS_HOST=${{Shop Redis.REDIS_HOST}}
MAIL_HOST=${{Shop Backend.MAIL_HOST}}Use the service's name, then a dot, then the key. Besides that service's own variables, every service provides:
- Any service
PRIVATE_HOST(its address inside your private network) andPUBLIC_URL.- PostgreSQL and MySQL
DATABASE_URL,DB_CONNECTION,DB_HOST,DB_PORT,DB_DATABASE,DB_USERNAME,DB_PASSWORD.- Redis
REDIS_URL,REDIS_HOST,REDIS_PORT,REDIS_PASSWORD.
Workers share their service's variables
A background worker added from a service gets a reference to each of that service's variables. A key you add to the service later reaches its workers automatically. A value you set on the worker itself is never overwritten. See Background workers.
Good to know
- Values are encrypted at rest and masked in the console. Reveal one only when you need it.
- Changing a variable is recorded in your activity history, without the value.
- Files you change from Shell don't persist, so keep settings in variables.
Staging and pull-request previews don't copy production values. Set what they need on their own environment.