Skip to content

Environment Variables

Environment variables provide a secure way to configure your applications with sensitive data, API keys, and environment-specific settings.

Environment variables are key-value pairs that configure your application’s runtime behavior without hardcoding values in your source code.

  • Security: Keep sensitive data out of your codebase
  • Flexibility: Different values for different environments
  • Configuration: Easy application configuration management
  • Portability: Same code works across environments
  1. Navigate to your application dashboard
  2. Go to SettingsEnvironment Variables
  3. Click “Add Variable”
  4. Enter:
    • Key: Variable name (e.g., DATABASE_URL)
    • Value: Variable value (e.g., postgresql://...)
    • Environment: Which environment(s) to apply to
Terminal window
curl -X POST \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"key": "DATABASE_URL",
"value": "postgresql://user:pass@host:5432/db",
"environment": "production"
}' \
https://api.easydeploy.com/v1/applications/APP_ID/env

Import multiple variables from a .env file:

Terminal window
# Upload .env file
curl -X POST \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "environment=production" \
https://api.easydeploy.com/v1/applications/APP_ID/env/import
Terminal window
# PostgreSQL
DATABASE_URL=postgresql://user:password@host:5432/database
DB_HOST=db.example.com
DB_PORT=5432
DB_NAME=myapp
DB_USER=myuser
DB_PASSWORD=secretpassword
# MongoDB
MONGODB_URI=mongodb://user:password@host:27017/database
# Redis
REDIS_URL=redis://user:password@host:6379
Terminal window
# Third-party APIs
STRIPE_SECRET_KEY=sk_live_...
SENDGRID_API_KEY=SG....
GOOGLE_ANALYTICS_ID=UA-...
FACEBOOK_APP_ID=123456789
# JWT and encryption
JWT_SECRET=your-super-secret-jwt-key
ENCRYPTION_KEY=32-character-encryption-key
SESSION_SECRET=session-secret-key
Terminal window
# Environment settings
NODE_ENV=production
DEBUG=false
LOG_LEVEL=info
PORT=3000
# Feature flags
FEATURE_NEW_UI=true
FEATURE_BETA_API=false
MAINTENANCE_MODE=false
# External services
CDN_URL=https://cdn.example.com
API_BASE_URL=https://api.example.com
WEBHOOK_URL=https://hooks.example.com
Terminal window
NODE_ENV=development
DEBUG=true
LOG_LEVEL=debug
DATABASE_URL=postgresql://localhost:5432/myapp_dev
API_BASE_URL=http://localhost:8000
STRIPE_SECRET_KEY=sk_test_...
Terminal window
NODE_ENV=staging
DEBUG=false
LOG_LEVEL=info
DATABASE_URL=postgresql://staging-db:5432/myapp_staging
API_BASE_URL=https://api-staging.example.com
STRIPE_SECRET_KEY=sk_test_...
Terminal window
NODE_ENV=production
DEBUG=false
LOG_LEVEL=error
DATABASE_URL=postgresql://prod-db:5432/myapp_prod
API_BASE_URL=https://api.example.com
STRIPE_SECRET_KEY=sk_live_...
  • Never commit environment variables to version control
  • Use strong passwords and random secrets
  • Rotate keys regularly for security
  • Limit access to production variables
  • Use UPPERCASE with underscores: DATABASE_URL
  • Be descriptive: STRIPE_SECRET_KEY vs KEY1
  • Group related variables: DB_HOST, DB_PORT, DB_NAME
  • Use consistent prefixes: AWS_ACCESS_KEY, AWS_SECRET_KEY
  • Separate environments: Different variables for dev/staging/prod
  • Team permissions: Limit who can view/edit variables
  • Audit logging: Track all variable changes
  • Read-only access: Some team members can view, not edit
Terminal window
// Access environment variables
const dbUrl = process.env.DATABASE_URL;
const apiKey = process.env.STRIPE_SECRET_KEY;
const port = process.env.PORT || 3000;
// Database connection
const db = require('pg').Client({
connectionString: process.env.DATABASE_URL
});
// API configuration
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);
Terminal window
import os
# Access environment variables
db_url = os.environ.get('DATABASE_URL')
api_key = os.environ.get('STRIPE_SECRET_KEY')
port = int(os.environ.get('PORT', 5000))
# Database connection
import psycopg2
conn = psycopg2.connect(os.environ['DATABASE_URL'])
# API configuration
import stripe
stripe.api_key = os.environ['STRIPE_SECRET_KEY']
Terminal window
<?php
// Access environment variables
$dbUrl = $_ENV['DATABASE_URL'];
$apiKey = $_ENV['STRIPE_SECRET_KEY'];
$port = $_ENV['PORT'] ?? 8000;
// Database connection
$pdo = new PDO($_ENV['DATABASE_URL']);
// API configuration
\Stripe\Stripe::setApiKey($_ENV['STRIPE_SECRET_KEY']);
?>
Terminal window
package main
import (
"os"
"strconv"
)
func main() {
// Access environment variables
dbURL := os.Getenv("DATABASE_URL")
apiKey := os.Getenv("STRIPE_SECRET_KEY")
port, err := strconv.Atoi(os.Getenv("PORT"))
if err != nil {
port = 8080
}
}

Update variables without redeploying:

Terminal window
curl -X PUT \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"value": "new-secret-value"
}' \
https://api.easydeploy.com/v1/applications/APP_ID/env/VARIABLE_KEY
  • Change tracking: View all variable changes
  • Rollback capability: Restore previous values
  • Audit logs: Who changed what and when
  • Encrypted storage: All variables encrypted at rest
  • Secure transmission: HTTPS for all API calls
  • Access logging: Track who accessed variables
  • Automatic rotation: Schedule key rotation

Create a .env file for local development:

Terminal window
# .env (do not commit to git!)
DATABASE_URL=postgresql://localhost:5432/myapp_dev
STRIPE_SECRET_KEY=sk_test_...
JWT_SECRET=your-local-secret
DEBUG=true
.env.development
NODE_ENV=development
API_URL=http://localhost:3000
# .env.staging
NODE_ENV=staging
API_URL=https://api-staging.example.com
# .env.production
NODE_ENV=production
API_URL=https://api.example.com

Always exclude environment files from git:

Terminal window
# Environment variables
.env
.env.local
.env.development
.env.staging
.env.production
.env.*.local
# Environment configuration
config/secrets.yml
config/database.yml

Variable not available in application

  • Check variable name spelling and case
  • Verify environment selection
  • Restart application after adding variables

Database connection fails

  • Verify DATABASE_URL format
  • Check database host accessibility
  • Confirm credentials are correct

API keys not working

  • Ensure using correct key for environment
  • Check API key permissions and quotas
  • Verify key format and encoding

List all environment variables:

Terminal window
# Node.js
console.log(process.env);
# Python
import os
print(os.environ)
# PHP
print_r($_ENV);
# Go
import "os"
for _, env := range os.Environ() {
fmt.Println(env)
}

Need help? Check our troubleshooting guide or contact support.