Setting Up Environment Variables
Create a.env file in your project root by copying the example:
.env with your actual values:
Environment Variable Functions
Guccho provides two utility functions for accessing environment variables in your configuration files:env() - Required Variables
Retrieves a required environment variable. If the variable is not set, Guccho will fail to start.Use this for:
- Essential credentials like database connections
- Required API keys
- Any configuration that must be present
The absence of a required variable will prevent Guccho from launching with a clear error message.
safeEnv() - Optional Variables
Retrieves an optional environment variable. Returns
undefined if not set.Use this for:- Optional configuration with sensible defaults
- Feature flags
- Non-critical settings
Common Environment Variables
Database Connection
MySQL database connection string.Format: Used in configuration:
mysql://username:password@host:port/databaseExample:Redis Connection
Redis server connection URL.Format: With authentication:Used in configuration:
redis://host:portDefault: redis://localhostExample:Required if you set
sessionStore: 'redis' in your backend configuration.Public Base URL
Public-facing base URL for your server. This is accessible in both server and client code.Example:
Variables prefixed with
NUXT_PUBLIC_ are exposed to the client-side code. See Nuxt runtime config for details.Production Deployment
IP address to bind the server to in production.Default:
0.0.0.0 (all interfaces)Example:Usage Examples
Required Database Connection
Optional Redis with Fallback
Multiple Fallback Levels
Backend Adapter Requirements
- bancho.py
Required:
DB_DSN- MySQL database connection
REDIS_URL- Redis connection (recommended for production)
Environment-Specific Configuration
Development
Production
Best Practices
Troubleshooting
”env validation error”
If you see this error, a required environment variable is missing or invalid:.env file.
Variables not loading
- Ensure
.envis in the project root directory - Restart the development server after changing
.env - Check for typos in variable names (they’re case-sensitive)
Connection refused errors
If database or Redis connections fail:- Verify the service is running:
mysqlorredis-cli - Check the connection string format
- Ensure firewall rules allow connections
- Test credentials manually
Next Steps
Backend Configuration
Use environment variables in backend config
UI Configuration
Configure UI settings and branding