Course/Chapter 2/4. Environment Variables & Configuration
    beginner
    Chapter 2: Hosting n8n — Self-Hosted vs Cloud

    4. Environment Variables & Configuration

    Master n8n configuration through environment variables.

    10m Lesson 4 of 5

    n8n is configured primarily through environment variables. Understanding the key variables lets you fine-tune your instance for your specific needs.

    Essential Variables

    • - N8N_HOST: Your n8n domain (e.g., n8n.example.com)
    • - N8N_PROTOCOL: http or https
    • - N8N_ENCRYPTION_KEY: Key for encrypting stored credentials
    • - EXECUTIONS_MODE: "regular" (default) or "queue" (for scaling)
    • - GENERIC_TIMEZONE: Default timezone (e.g., "America/New_York")

    Code Examples

    Common Environment Variables
    bash
    # Core settings
    N8N_HOST=n8n.example.com
    N8N_PROTOCOL=https
    N8N_ENCRYPTION_KEY=random-32-char-string
    GENERIC_TIMEZONE=America/New_York
    
    # Execution settings
    EXECUTIONS_MODE=regular
    EXECUTIONS_TIMEOUT=300
    EXECUTIONS_DATA_PRUNE=true
    EXECUTIONS_DATA_MAX_AGE=168
    
    # Database
    DB_TYPE=postgresdb
    DB_POSTGRESDB_HOST=localhost
    DB_POSTGRESDB_PORT=5432
    DB_POSTGRESDB_DATABASE=n8n
    
    # Security
    N8N_BASIC_AUTH_ACTIVE=true
    N8N_BASIC_AUTH_USER=admin
    N8N_BASIC_AUTH_PASSWORD=secure_password

    Pro Tips

    • 💡Set EXECUTIONS_DATA_PRUNE=true to automatically clean up old execution data
    • 💡Use GENERIC_TIMEZONE to ensure date/time functions work correctly for your location

    Comprehension Quiz

    Answer 2 of 2 correctly to unlock lesson completion.

    1. What does N8N_ENCRYPTION_KEY do?

    2. Which execution mode is used for horizontal scaling?

    Pass the quiz above to unlock lesson completion