Environment Variables

Configure your apps with environment variables for secrets, feature flags, and runtime settings.

Overview

Environment variables let you pass configuration to your app without hardcoding values in source code. They're the standard way to manage secrets (API keys, database URLs) and per-environment settings (debug mode, log level).

On Kapable, environment variables are:

Setting Variables via Console

  1. Go to Apps > {your app} > Settings
  2. Scroll to the Environment section
  3. Enter a key and value, then click Add
  4. Click Rebuild to apply changes

Variables are key-value pairs. Keys must be uppercase letters, digits, and underscores (e.g. DATABASE_URL, STRIPE_SECRET_KEY).

Bulk Import

You can paste a .env file format in the bulk import section:

DATABASE_URL=postgres://user:pass@host:5432/db
REDIS_URL=redis://localhost:6379
SECRET_KEY=your-secret-here

Each KEY=VALUE line will be parsed and added. Lines starting with # are ignored.

Setting Variables via API

# Set a single variable
curl -X POST https://api.kapable.ai/v1/apps/{app_id}/env \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"key": "DATABASE_URL", "value": "postgres://..."}'

# List all variables (values are masked)
curl https://api.kapable.ai/v1/apps/{app_id}/env \
  -H "Authorization: Bearer YOUR_API_KEY"

# Delete a variable
curl -X DELETE https://api.kapable.ai/v1/apps/{app_id}/env/DATABASE_URL \
  -H "Authorization: Bearer YOUR_API_KEY"

Built-in Variables

Kapable automatically provides these variables to every app:

VariableDescriptionExample
PORTPort your app must listen on3000
KAPABLE_APP_IDYour app's unique UUIDa1b2c3d4-...
KAPABLE_APP_SLUGYour app's URL slugmy-app
KAPABLE_ORG_IDYour organisation's UUIDe5f6g7h8-...
KAPABLE_ORG_SLUGYour organisation's slugacme
NODE_ENVSet to production for Node.js appsproduction
RUST_LOGDefault log level for Rust appsinfo
Always use PORT

Always use PORT for your listening port. Do not hardcode a port number.

const port = process.env.PORT || 3000;
app.listen(port);
let port = std::env::var("PORT").unwrap_or_else(|_| "3000".into());

Best Practices

Never Commit Secrets

Add .env to your .gitignore. Use environment variables for all sensitive values:

Use Descriptive Names

Prefix variables by purpose:

DB_HOST=...
DB_PORT=...
DB_NAME=...
STRIPE_SECRET_KEY=...
STRIPE_WEBHOOK_SECRET=...
SMTP_HOST=...
SMTP_PORT=...

Separate Environments

Don't reuse the same variables across dev, staging, and production. Each Kapable app has its own environment, so create separate apps for each stage:

Secret Rotation

To rotate a secret:

  1. Generate the new secret value
  2. Update the environment variable in App Settings > Environment
  3. Click Rebuild to redeploy with the new value
  4. Revoke the old secret in the external service
Zero-downtime rotation

Some apps support reading multiple keys simultaneously. Set both API_KEY and API_KEY_OLD, deploy, then remove the old one in a second deploy.

Variable Size Limits

Troubleshooting

Next Steps