Required Variables
These variables must be set for VIJ Admin to function.MONGODB_URI
MongoDB connection string for storing error logs.Format: Connection Options:
mongodb://[username:password@]host[:port]/database[?options]Examples:retryWrites=true- Automatically retry write operationsw=majority- Write concern for data durabilityauthSource=admin- Database for authenticationssl=true- Enable SSL/TLS encryptionmaxPoolSize=50- Maximum connection pool sizeminPoolSize=10- Minimum connection pool size
NEXT_PUBLIC_BASE_URL
The public URL where your VIJ Admin dashboard is accessible.Usage: Used for API endpoints, redirects, and client-side routing.Format: Complete URL with protocol (http/https) and domain/port.Examples:
Update this variable when:
- Changing domains
- Moving from development to production
- Changing ports
- Adding/removing SSL
Optional Variables
These variables enable additional features or customize behavior.GEMINI_API_KEY
Google Gemini API key for AI-powered error analysis.Get a key: Visit ai.google.dev to create an API key.Example:Features Enabled:
- AI error summaries
- Root cause analysis
- Suggested fixes
- Pattern detection
- VIJ works normally
- AI features are disabled
- No error messages shown
NODE_ENV
Node.js environment mode.Values:Effects:
development- Development mode with debugging enabledproduction- Production mode with optimizationstest- Test mode (used for automated testing)
Development
Production
| Feature | Development | Production |
|---|---|---|
| Error details | Full stack traces | Sanitized errors |
| Logging | Verbose | Minimal |
| Optimizations | Disabled | Enabled |
| Source maps | Enabled | Disabled |
| Cache | Disabled | Enabled |
PORT
Port number for the Next.js server.Examples:
Default
Custom Port
Production (Behind Proxy)
When using a reverse proxy (Nginx, Apache), you typically keep this at 3000 and configure the proxy to forward requests.
MONGODB_OPTIONS
Additional MongoDB connection options as JSON.Example:Common Options:
LOG_RETENTION_DAYS
Number of days to retain logs before automatic deletion.Examples:Behavior:
30 Days
1 Year
Disabled (Keep Forever)
- Logs older than this value are deleted automatically
- Deletion runs daily at midnight UTC
- Set to
0to disable automatic deletion
ENABLE_TELEMETRY
Enable anonymous usage telemetry for VIJ development.Values: Data Collected (if enabled):
true or falseExamples:Enabled
Disabled
- Installation count
- Feature usage (anonymized)
- Error rates (aggregate only)
- No PII or error content
Telemetry helps improve VIJ. All data is anonymous and aggregated. You can disable it anytime.
Environment-Specific Configuration
Development (.env.local)
.env.local
Production (.env.production)
.env.production
Staging (.env.staging)
.env.staging
Platform-Specific Configuration
Vercel
Set environment variables in the Vercel dashboard:- Go to Project Settings → Environment Variables
- Add variables for each environment (Production, Preview, Development)
- Deploy
Docker
Pass environment variables via Docker run command:Docker Compose
docker-compose.yml
Kubernetes
Use Kubernetes secrets:Loading Environment Variables
Next.js Built-in Support
Next.js automatically loads:.env.local- All environments (git-ignored).env.production- Production builds.env.development- Development builds.env- All environments (committed to git)
process.env(system environment).env.$(NODE_ENV).local.env.local(not loaded whenNODE_ENV=test).env.$(NODE_ENV).env
Manual Loading (Node.js)
For scripts or custom tooling:Environment File Template
Create.env.example for documentation:
.env.example
Security Best Practices
Never commit secrets
Never commit secrets
Add to
.gitignore:.gitignore
Use different keys per environment
Use different keys per environment
Rotate secrets regularly
Rotate secrets regularly
- MongoDB passwords: Every 90 days
- API keys: Every 180 days
- Update in all environments
- Document rotation in runbook
Use secret management services
Use secret management services
For production:
- AWS Secrets Manager
- HashiCorp Vault
- Azure Key Vault
- Google Secret Manager
Validate environment variables on startup
Validate environment variables on startup
lib/config.ts
Troubleshooting
Environment variables not loading
Environment variables not loading
Issue: Variables are
undefined at runtimeSolutions:- Check file name is exactly
.env.local(not.env.txtor.env) - Restart dev server after changes
- Ensure no typos in variable names
- Check
.env.localis in project root - For client-side variables, use
NEXT_PUBLIC_prefix
NEXT_PUBLIC_ variables not available in client
NEXT_PUBLIC_ variables not available in client
Issue: Client code cannot access environment variablesSolution: Use
NEXT_PUBLIC_ prefixMongoDB connection string format errors
MongoDB connection string format errors
Issue: Invalid connection string formatCommon mistakes:URL-encode special characters in passwords:
@→%40:→%3A/→%2F?→%3F#→%23
Vercel environment variables not updating
Vercel environment variables not updating
Issue: Changes to environment variables not reflectedSolution:
- Update variables in Vercel dashboard
- Trigger a new deployment (redeploy or push commit)
- Environment variables are set at build time, not runtime
Next Steps
Dashboard Setup
Complete setup guide for VIJ Admin
Deployment Guide
Deploy VIJ Admin to production
SDK Configuration
Configure the vij-sdk client
Quickstart
Get started with VIJ in minutes