Skip to main content
Environment variables allow you to configure your Edge Compute functions without modifying code. They’re ideal for non-sensitive configuration values like API endpoints, feature flags, and performance settings that you want to manage alongside your function code.

Overview

Environment variables in Edge Compute are:
  • Declared in configuration — Defined in your function’s func.toml
  • Injected at deployment — Available when your function starts
  • Function-scoped — Specific to each function
  • Version controlled — Part of your function’s configuration

Defining Environment Variables

Define environment variables in your func.toml under the [env_vars] section:
[edge_compute]
func_id = "your-function-id"
func_name = "my-function"

[env_vars]
SERVICE_NAME = "data-processor"
VERSION = "1.0.0"
LOG_LEVEL = "info"
DEBUG = "false"
MAX_FILE_SIZE = "10485760"
CACHE_TTL = "3600"
API_BASE_URL = "https://api.example.com"
All values are stored as strings. Parse them to the appropriate type in your code.

Accessing Environment Variables

class Config {
    constructor() {
        this.serviceName = process.env.SERVICE_NAME || 'unknown-service';
        this.apiUrl = process.env.API_BASE_URL;
        this.debug = process.env.DEBUG === 'true';
        this.cacheTtl = parseInt(process.env.CACHE_TTL || '300', 10);
        this.maxFileSize = parseInt(process.env.MAX_FILE_SIZE || '10485760', 10);
    }
}

const config = new Config();

export async function handler(request) {
    return new Response(JSON.stringify({
        service: config.serviceName,
        api_configured: !!config.apiUrl,
        cache_ttl: config.cacheTtl,
        debug: config.debug
    }), {
        headers: { 'Content-Type': 'application/json' }
    });
}

Environment Variables vs Secrets

Use environment variables for non-sensitive configuration. For sensitive data like API keys and passwords, use Secrets instead.
FeatureEnvironment VariablesSecrets
StoragePlain text in func.tomlEncrypted in Telnyx infrastructure
ScopeFunction-specificOrganization-wide
Version Control✅ Yes (in git)❌ No (separate secure storage)
Use CaseConfiguration, feature flagsAPI keys, passwords, tokens

When to Use Each

Perfect for non-sensitive configuration:
  • Application settingsLOG_LEVEL, DEBUG_MODE, PORT
  • Feature flagsENABLE_CACHING, MAINTENANCE_MODE
  • Performance tuningMAX_FILE_SIZE, BATCH_SIZE, TIMEOUT
  • Public endpointsAPI_BASE_URL, CDN_URL, WEBHOOK_URL
  • Environment identifiersENVIRONMENT, VERSION, SERVICE_NAME

CLI Management

Manage environment variables by editing your func.toml file directly, then redeploy:
# Edit func.toml to add/update env_vars
vim func.toml

# Deploy function with updated environment variables
telnyx-edge ship
Environment variable changes take effect on the next deployment.

Best Practices

Naming Conventions

Use UPPER_SNAKE_CASE for consistency with standard environment variable conventions:
[env_vars]
# ✅ Good: Descriptive and consistent
SERVICE_NAME = "data-processor"
MAX_FILE_SIZE = "10485760"
DATABASE_TIMEOUT = "30"
ENABLE_CACHING = "true"

# ❌ Avoid: Vague or inconsistent naming
name = "processor"
maxsize = "10485760"

Type Safety

Store all values as strings and parse them in your code:
[env_vars]
MAX_CONNECTIONS = "100"
TIMEOUT_SECONDS = "30"
ENABLE_FEATURE = "true"

Validation and Defaults

Always validate environment variables and provide sensible defaults:
function getEnvInt(key, defaultVal) {
    const raw = process.env[key];
    if (raw === undefined || !/^-?\d+$/.test(raw)) {
        return defaultVal;
    }
    return parseInt(raw, 10);
}

function getConfig() {
    return {
        maxFileSize: getEnvInt('MAX_FILE_SIZE', 10485760),
        batchSize: Math.max(1, getEnvInt('BATCH_SIZE', 100)),
        timeout: Math.max(1, getEnvInt('TIMEOUT', 30)),
        debug: process.env.DEBUG?.toLowerCase() === 'true',
    };
}

Environment-Specific Values

Use descriptive variable names and document expected values:
[env_vars]
# Environment identification
ENVIRONMENT = "production"  # development, staging, production
LOG_LEVEL = "warn"          # debug, info, warn, error

# Feature flags
DEBUG_MODE = "false"
METRICS_ENABLED = "true"

Common Patterns

Feature Flags

[env_vars]
ENABLE_NEW_PROCESSING = "true"
ENABLE_BULK_OPERATIONS = "false"
ENABLE_ADVANCED_LOGGING = "true"
BETA_FEATURES_ENABLED = "false"

Service Configuration

[env_vars]
SERVICE_NAME = "user-auth-service"
SERVICE_VERSION = "2.1.0"
ENVIRONMENT = "production"

API_BASE_URL = "https://api.telnyx.com"
CDN_BASE_URL = "https://cdn.telnyx.com"

Performance Tuning

[env_vars]
MAX_CONNECTIONS = "100"
CONNECTION_TIMEOUT = "30"
READ_TIMEOUT = "60"

BATCH_SIZE = "50"
MAX_RETRIES = "3"
RETRY_DELAY_MS = "1000"

Debugging

Print environment variables for debugging during development:
function debugEnvVars() {
    const keys = ['SERVICE_NAME', 'API_BASE_URL', 'DEBUG', 'LOG_LEVEL'];
    console.log('=== Environment Variables ===');
    for (const key of keys) {
        const value = process.env[key] || '(not set)';
        console.log(`${key} = ${value}`);
    }
}
Remove debug logging before deploying to production to avoid exposing configuration details.

Limits

Environment variables are subject to the following constraints:
  • Variable names must contain only letters, numbers, and underscores
  • Variable names are case-sensitive
  • All values are stored and retrieved as strings
For specific size limits on variable names and values, refer to the Edge Compute limits documentation.