Environment Variables
Environment variables let you configure your application without hardcoding values.
Adding Variables
In the App
- Go to the deployment detail
- Click Environment Variables
- Click Add Variable
- Enter name and value
- Click Save
Common Variables
| Variable | Purpose | Example |
|---|---|---|
DATABASE_URL | Database connection | postgres://user:pass@host/db |
SECRET_KEY | Application secret | your-secret-key |
NODE_ENV | Node.js environment | production |
PORT | Server port | 3000 |
API_KEY | External service key | sk_live_... |
Variable Behavior
Build Time
Variables are available during docker build:
ARG DATABASE_URLRUN echo "Building with DB: $DATABASE_URL"Runtime
Variables are injected when the container starts:
// In your appconst dbUrl = process.env.DATABASE_URL;Security
Encryption
- Variables are encrypted at rest in the database
- Decrypted only when needed for builds/runs
- Never logged in plain text
Best Practices
DO:
- Use variables for secrets and configuration
- Rotate secrets periodically
- Use different values for staging/production
DON’T:
- Commit secrets to Git
- Log environment variables
- Share production secrets
Special Variables
PORT
Expose automatically sets PORT based on your framework’s default:
| Framework | Default PORT |
|---|---|
| Node.js | 3000 |
| Python | 8000 |
| Go | 8080 |
| Rust | 8080 |
| Ruby | 3000 |
You can override this in your environment variables.
Reserved Variables
These are set automatically:
| Variable | Description |
|---|---|
PORT | Server port (can override) |
NODE_ENV | Set to production for Node.js |
Per-Environment Setup
For different environments, create separate deployments:
Production (api.hosted.domain.com)
DATABASE_URL=postgres://prod-db/appNODE_ENV=productionLOG_LEVEL=warnStaging (api-staging.hosted.domain.com)
DATABASE_URL=postgres://staging-db/appNODE_ENV=stagingLOG_LEVEL=debugLoading from .env
If your project has a .env file:
- It’s included in the build context
- Your app can load it at runtime
- But container ENV takes precedence
Example with dotenv (Node.js):
require('dotenv').config();
// - Uses container ENV if set// - Falls back to .env fileUpdating Variables
Changes to environment variables:
- Are saved immediately
- Require a redeploy to take effect
- Don’t affect the running container until redeployed
To apply changes:
- Update variables
- Click Redeploy
Exporting/Importing
Currently, variables must be set manually per deployment. Future versions may support:
- Export to file
- Import from file
- Copy between deployments