Environment Variables
Environment variables allow you to configure your application without changing code. Deployxa provides secure, encrypted environment variable management for all your projects.
Overview
Environment variables are used to:
- Store API keys and secrets
- Configure database connections
- Set application settings
- Manage feature flags
- Configure third-party services
Features:
- Encrypted storage
- Multiple scopes (Production, Preview, Development)
- Bulk import/export
- Version history
- Access control
Adding Environment Variables
From Dashboard
- Go to Project → Environment
- Click "Add Variable"
- Enter variable details:
- Name: Variable name (e.g.,
DATABASE_URL) - Value: Variable value
- Scope: Production, Preview, Development, or All
- Encrypted: Toggle encryption (recommended for secrets)
- Name: Variable name (e.g.,
- Click "Save"
From CLI
deployxa env add DATABASE_URL postgresql://user:pass@host:5432/db --project my-app
deployxa env add API_KEY sk_test_123 --project my-app --encrypted
From API
POST /api/projects/{projectId}/env
{
"key": "DATABASE_URL",
"value": "postgresql://user:pass@host:5432/db",
"encrypted": true,
"environment": "production"
}
Variable Naming
Naming Rules
- Use uppercase letters
- Use underscores to separate words
- Start with a letter
- No spaces or special characters (except underscores)
- Maximum 255 characters
Valid Examples
DATABASE_URL
API_KEY
SECRET_KEY
NODE_ENV
APP_NAME
STRIPE_SECRET_KEY
Invalid Examples
database-url # ❌ Use underscores
api key # ❌ No spaces
123_API_KEY # ❌ Cannot start with number
API-KEY # ❌ Use underscores, not hyphens
Variable Scopes
Production
Variables available in production deployments:
- Live applications
- Custom domains
- Production environment
DATABASE_URL=postgresql://prod-host:5432/db
API_KEY=prod_api_key_123
Preview
Variables available in preview deployments:
- Pull request deployments
- Preview URLs
- Testing environment
DATABASE_URL=postgresql://preview-host:5432/db
API_KEY=preview_api_key_123
Development
Variables available in development:
- Local development
- Development environment
DATABASE_URL=postgresql://localhost:5432/db
API_KEY=dev_api_key_123
All Environments
Variables available in all environments:
APP_NAME=MyApp
NODE_ENV=production
Encryption
Encrypted Variables
Encrypted variables are:
- Encrypted at rest using AES-256
- Never logged or displayed in plain text
- Only accessible to your application
- Masked in the dashboard
When to encrypt:
- API keys
- Secret keys
- Database passwords
- Private keys
- OAuth secrets
Unencrypted Variables
Unencrypted variables are:
- Stored in plain text
- Visible in the dashboard
- Logged in build logs
When not to encrypt:
- Public configuration
- Feature flags
- Non-sensitive settings
- Public URLs
Toggling Encryption
- Go to Project → Environment
- Find the variable
- Click the lock icon
- Toggle encryption
- Click "Save"
Note: Changing encryption requires redeployment.
Using Environment Variables
Node.js / JavaScript
// Access environment variable
const apiUrl = process.env.API_URL;
const dbUrl = process.env.DATABASE_URL;
// With default value
const port = process.env.PORT || 3000;
// Check if variable exists
if (process.env.API_KEY) {
// Use API key
}
Python
import os
# Access environment variable
api_url = os.environ.get('API_URL')
db_url = os.getenv('DATABASE_URL')
# With default value
port = int(os.environ.get('PORT', 8000))
# Check if variable exists
if 'API_KEY' in os.environ:
# Use API key
pass
PHP
// Access environment variable
$apiUrl = getenv('API_URL');
$dbUrl = $_ENV['DATABASE_URL'];
// With default value
$port = getenv('PORT') ?: 8000;
// Check if variable exists
if (getenv('API_KEY')) {
// Use API key
}
Ruby
# Access environment variable
api_url = ENV['API_URL']
db_url = ENV['DATABASE_URL']
# With default value
port = ENV.fetch('PORT', 8000)
# Check if variable exists
if ENV['API_KEY']
# Use API key
end
Java
// Access environment variable
String apiUrl = System.getenv("API_URL");
String dbUrl = System.getenv("DATABASE_URL");
// With default value
String port = System.getenv().getOrDefault("PORT", "8080");
// Check if variable exists
if (System.getenv("API_KEY") != null) {
// Use API key
}
Go
import "os"
// Access environment variable
apiUrl := os.Getenv("API_URL")
dbUrl := os.Getenv("DATABASE_URL")
// With default value
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
// Check if variable exists
if _, exists := os.LookupEnv("API_KEY"); exists {
// Use API key
}
Rust
use std::env;
// Access environment variable
let api_url = env::var("API_URL").unwrap_or_default();
let db_url = env::var("DATABASE_URL").unwrap_or_default();
// With default value
let port = env::var("PORT").unwrap_or_else(|_| "8080".to_string());
// Check if variable exists
if env::var("API_KEY").is_ok() {
// Use API key
}
Common Environment Variables
Node.js
NODE_ENV=production
PORT=3000
DATABASE_URL=postgresql://user:pass@host:5432/db
REDIS_URL=redis://user:pass@host:6379
API_KEY=your-api-key
JWT_SECRET=your-jwt-secret
Python
PYTHON_ENV=production
DATABASE_URL=postgresql://user:pass@host:5432/db
SECRET_KEY=your-secret-key
DEBUG=False
ALLOWED_HOSTS=example.com
PHP / Laravel
APP_ENV=production
APP_KEY=base64:your-app-key
APP_DEBUG=false
DB_CONNECTION=mysql
DB_HOST=host
DB_PORT=3306
DB_DATABASE=dbname
DB_USERNAME=user
DB_PASSWORD=pass
Ruby / Rails
RAILS_ENV=production
SECRET_KEY_BASE=your-secret-key
DATABASE_URL=postgresql://user:pass@host:5432/db
RAILS_LOG_TO_STDOUT=true
RAILS_SERVE_STATIC_FILES=true
Java / Spring Boot
SPRING_PROFILES_ACTIVE=production
SERVER_PORT=8080
SPRING_DATASOURCE_URL=jdbc:postgresql://host:5432/db
SPRING_DATASOURCE_USERNAME=user
SPRING_DATASOURCE_PASSWORD=pass
Bulk Operations
Import Variables
Import from .env file:
- Go to Project → Environment
- Click "Import"
- Select your
.envfile - Review variables
- Click "Import"
Example .env file:
DATABASE_URL=postgresql://user:pass@host:5432/db
API_KEY=your-api-key
SECRET_KEY=your-secret-key
NODE_ENV=production
Export Variables
Export to .env file:
- Go to Project → Environment
- Click "Export"
- Select format (env, json, yaml)
- Select scope
- Click "Export"
Delete Multiple Variables
- Go to Project → Environment
- Select variables (checkbox)
- Click "Delete Selected"
- Confirm deletion
Variable History
Viewing History
- Go to Project → Environment
- Click on a variable
- Click "History"
- View change history
History Includes
- Previous values
- Change date
- Changed by
- Change reason (if provided)
Restoring Previous Values
- Go to Project → Environment
- Click on a variable
- Click "History"
- Find the version to restore
- Click "Restore"
- Confirm restoration
Access Control
Who Can View Variables
- Owners: Full access to all variables
- Admins: Full access to all variables
- Developers: View and edit variables for assigned projects
Who Can Edit Variables
- Owners: Can edit all variables
- Admins: Can edit all variables
- Developers: Can edit variables for assigned projects
Audit Logs
All variable changes are logged:
- Who made the change
- When the change was made
- What was changed
- Previous value (encrypted)
Security Best Practices
Do's
✅ Use encryption for sensitive data ✅ Rotate secrets regularly ✅ Use different values per environment ✅ Document required variables ✅ Use descriptive variable names ✅ Review access permissions regularly
Don'ts
❌ Never commit .env files to Git
❌ Never share secrets in plain text
❌ Never use the same secret across environments
❌ Never log sensitive variables
❌ Never hardcode secrets in code
❌ Never use weak or predictable secrets
Secret Rotation
Rotate secrets regularly:
- Generate new secret
- Add new variable with new value
- Deploy application
- Verify application works
- Remove old variable
- Deploy again
Environment Separation
Use different values per environment:
# Production
DATABASE_URL=postgresql://prod-host:5432/db
API_KEY=prod_key_123
# Preview
DATABASE_URL=postgresql://preview-host:5432/db
API_KEY=preview_key_123
# Development
DATABASE_URL=postgresql://localhost:5432/db
API_KEY=dev_key_123
Troubleshooting
Variable Not Available
Problem: Environment variable is undefined
Solution:
- Check variable name is correct
- Verify variable is set in correct scope
- Redeploy application
- Check application code
- Verify variable is not misspelled
Encrypted Variable Not Decrypting
Problem: Encrypted variable shows as encrypted string
Solution:
- Verify encryption is enabled
- Check application has access
- Redeploy application
- Check encryption key is valid
- Contact support if issue persists
Variable Not Updating
Problem: Variable changes not reflected
Solution:
- Redeploy application
- Clear application cache
- Check variable scope
- Verify variable name
- Check for caching in application
Import Failed
Problem: Cannot import .env file
Solution:
- Check file format is correct
- Verify file encoding (UTF-8)
- Check for syntax errors
- Verify file permissions
- Try manual import
Advanced Features
Variable References
Reference other variables:
DATABASE_URL=postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432/${DB_NAME}
Variable Validation
Validate variables before deployment:
# Required variables
DATABASE_URL
API_KEY
SECRET_KEY
# Optional variables
DEBUG=false
LOG_LEVEL=info
Variable Groups
Organize variables into groups:
# Database
DB_HOST=localhost
DB_PORT=5432
DB_NAME=mydb
DB_USER=user
DB_PASSWORD=pass
# API
API_URL=https://api.example.com
API_KEY=your-api-key
API_SECRET=your-api-secret
Dynamic Variables
Generate variables dynamically:
# Timestamp
DEPLOY_TIME=2024-01-15T12:00:00Z
# Commit hash
COMMIT_HASH=abc123def456
# Build number
BUILD_NUMBER=42
Related Topics
Resources
Need Help? Contact support@deployxa.com or join our community Discord.