Skip to content

Environment Variables

Environment variables let you configure your application without hardcoding values.

Adding Variables

In the App

  1. Go to the deployment detail
  2. Click Environment Variables
  3. Click Add Variable
  4. Enter name and value
  5. Click Save

Common Variables

VariablePurposeExample
DATABASE_URLDatabase connectionpostgres://user:pass@host/db
SECRET_KEYApplication secretyour-secret-key
NODE_ENVNode.js environmentproduction
PORTServer port3000
API_KEYExternal service keysk_live_...

Variable Behavior

Build Time

Variables are available during docker build:

ARG DATABASE_URL
RUN echo "Building with DB: $DATABASE_URL"

Runtime

Variables are injected when the container starts:

// In your app
const 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:

FrameworkDefault PORT
Node.js3000
Python8000
Go8080
Rust8080
Ruby3000

You can override this in your environment variables.

Reserved Variables

These are set automatically:

VariableDescription
PORTServer port (can override)
NODE_ENVSet to production for Node.js

Per-Environment Setup

For different environments, create separate deployments:

Production (api.hosted.domain.com)

DATABASE_URL=postgres://prod-db/app
NODE_ENV=production
LOG_LEVEL=warn

Staging (api-staging.hosted.domain.com)

DATABASE_URL=postgres://staging-db/app
NODE_ENV=staging
LOG_LEVEL=debug

Loading from .env

If your project has a .env file:

  1. It’s included in the build context
  2. Your app can load it at runtime
  3. But container ENV takes precedence

Example with dotenv (Node.js):

process.env.DATABASE_URL
require('dotenv').config();
// - Uses container ENV if set
// - Falls back to .env file

Updating Variables

Changes to environment variables:

  1. Are saved immediately
  2. Require a redeploy to take effect
  3. Don’t affect the running container until redeployed

To apply changes:

  1. Update variables
  2. 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