Overview
Better Uptime uses environment variables for configuration. Variables can be set in a.env file in the project root or packages/config/.env.
Required Variables
These variables must be set for Better Uptime to function:Database
PostgreSQL connection stringFormat:
postgresql://user:password@host:5432/databaseExample: postgresql://postgres:mypassword@localhost:5432/better_uptimeAuthentication
Secret key for JWT token signingDevelopment: Can use
dev-secretProduction: Must use cryptographically secure random stringGenerate: openssl rand -base64 32GitHub OAuth
GitHub OAuth application client IDCreate at: https://github.com/settings/developers
GitHub OAuth application client secretAvailable after creating GitHub OAuth app
Email Service
Resend API key for sending emailsGet your API key at: https://resend.com/api-keys
Redis Configuration
Redis server hostname or IP addressDevelopment (Docker):
redisProduction (Docker): redis or 127.0.0.1Production (PM2): 127.0.0.1Redis server port
Redis username (for Redis 6+ ACL)Development:
defaultProduction: Set if using Redis ACL, otherwise leave emptyRedis password for authenticationDevelopment:
dev-passwordProduction: Strong random password (required)Generate: openssl rand -base64 32Service Configuration
Backend
Port for the backend tRPC API server
Node environment modeValues:
development, productionFrontend
Port for the Next.js frontend application
Public URL for the backend APIDevelopment:
http://localhost:8084Production: http://your-backend-url:8084Must be prefixed with
NEXT_PUBLIC_ to be accessible in the browserEnable polling for file changes (useful in Docker)Development:
true (recommended for Docker)Production: Not neededGitHub OAuth client ID exposed to the browserAutomatically set from
CLIENT_ID_GITHUB by Next.js build processUsually not needed to set manually - Next.js copies from
CLIENT_ID_GITHUBOverride the tRPC API URLDefaults to
NEXT_PUBLIC_BACKEND_URL if not setUse case: Custom API routing or proxy configurationAPI proxy target for Next.js rewritesUsed in development to proxy API requestsExample:
http://localhost:8084Worker
Geographic region identifier for the workerUsed for organizing workers by location
Unique identifier for the worker instanceUse different IDs when scaling workers (e.g.,
worker-1, worker-2, worker-3)Optional Variables
ClickHouse (Analytics)
ClickHouse is optional and used for storing uptime check metrics.ClickHouse server URLExample:
https://clickhouse.example.com:8443Leave empty to disable ClickHouse integrationClickHouse username
ClickHouse password
ClickHouse database name
Table name for storing uptime check metrics
Status Pages
CNAME target for custom status page domainsDevelopment:
localhost (default)Production: status.raashed.xyz (default)Override to use your own domain for status pagesPrefix for TXT verification recordsUsed when verifying custom domain ownershipFormat:
{prefix}.yourdomain.comEnvironment Templates
Development Template
Create.env with these values for local development:
.env
Production Template
Create.env with these values for production:
.env
Security Best Practices
Generate Strong Secrets
Generate Strong Secrets
Use cryptographically secure random strings for all secrets:
Protect Environment Files
Protect Environment Files
- Add
.envto.gitignore - Never commit secrets to version control
- Use different
.envfiles for each environment - Set restrictive file permissions:
chmod 600 .env
Rotate Secrets Regularly
Rotate Secrets Regularly
- Change JWT_SECRET periodically (will invalidate existing tokens)
- Rotate Redis password with zero downtime using Redis ACL
- Update OAuth secrets if compromised
Use Secrets Management
Use Secrets Management
For production deployments, consider using:
- AWS Secrets Manager
- HashiCorp Vault
- Docker Secrets
- Kubernetes Secrets
Environment Variable Loading
Better Uptime loads environment variables in this order:- System environment variables (highest priority)
.envfile in project rootpackages/config/.env- Default values (lowest priority)
Docker-Specific Notes
Service Networking
When running in Docker:Host Access
For services running on the host to connect to Docker Redis:Volume Mounts (Development)
Development configuration mounts source code:- Hot reload works automatically
- Changes persist across container restarts
- No need to set additional environment variables
Troubleshooting
Environment Variables Not Loading
Environment Variables Not Loading
- Check file location (project root or
packages/config/) - Verify file is named exactly
.env(notenv.txtor.env.local) - Ensure no syntax errors (no spaces around
=) - Restart services after changing
.env
Redis Connection Failed
Redis Connection Failed
- Verify
REDIS_HOSTis correct for your environment - Check
REDIS_PASSWORDmatches Redis configuration - Ensure Redis port is exposed (Docker)
- Test connection:
redis-cli -h $REDIS_HOST -p $REDIS_PORT -a $REDIS_PASSWORD ping
Backend URL Not Working
Backend URL Not Working
- Check
NEXT_PUBLIC_BACKEND_URLis set - Verify URL is accessible from browser
- Ensure backend service is running
- Check for CORS issues in browser console
JWT Token Issues
JWT Token Issues
- Verify
JWT_SECRETis set and consistent across services - Changing
JWT_SECRETinvalidates all existing tokens - Users will need to log in again after secret change
Next Steps
Development Setup
Set up local development environment
Production Deployment
Deploy to production
Database Setup
Configure PostgreSQL database