Environment Variables

↓ Download .md

Environment Variables

Configure environment variables for your application securely.

Adding Variables

  1. On the app edit screen, go to the Environment Variables section
  2. Add variables in KEY=value format, one per line
  3. Click Save & Restart to apply
DATABASE_URL=postgresql://user:pass@localhost:5432/app
REDIS_URL=redis://default:pass@localhost:6379
API_KEY=sk-abc123
NODE_ENV=production

Best Practices

Never put secrets in code

Always use environment variables for:

  • Database connection strings
  • API keys and tokens
  • Passwords and credentials
  • External service URLs

Use descriptive names

# Good
DATABASE_URL=...
SMTP_HOST=...
STRIPE_SECRET_KEY=...

# Avoid
DB=...
HOST=...
KEY=...

Common Variables by Framework

Node.js / Express / Next.js

NODE_ENV=production
PORT=3000
DATABASE_URL=...

Python / Django

DJANGO_SETTINGS_MODULE=myapp.settings.production
DATABASE_URL=...
SECRET_KEY=...
ALLOWED_HOSTS=*

Go

PORT=8080
DATABASE_URL=...
GIN_MODE=release

Referencing Other Apps

Since all apps in a stack run in the same pod, they communicate via localhost. Each service uses its default port:

# PostgreSQL in the same stack
DATABASE_URL=postgresql://user:pass@localhost:5432/defaultdb

# Redis in the same stack
REDIS_URL=redis://default:pass@localhost:6379

# MongoDB in the same stack
MONGO_URL=mongodb://user:pass@localhost:27017/defaultdb?authSource=admin

When Variables Are Applied

Variables are injected into the container at startup. This means:

  • Save & Restart is required to apply changes
  • Your application reads variables via process.env (Node.js), os.environ (Python), os.Getenv (Go), etc.
  • Variables are not visible in build logs