Overview
Walle uses environment variables for configuration across different deployment environments. All configuration is managed through a.env file in the project root, loaded by @nestjs/config in src/app.module.ts:12.
Required Environment Variables
PostgreSQL Configuration
PostgreSQL is used for storing telemetry points with table partitioning..env
PostgreSQL server hostname or IP address. Use
localhost for local development.PostgreSQL server port. Default is 5432.
Database user with full privileges on the target database.
Password for the PostgreSQL user.
Target database name. Must have PostGIS extension enabled.
TypeORM synchronization setting. Must be
false to allow manual partition management. Set in src/app/database/config/database-postgresql.config.ts:16.MongoDB Configuration
Walle connects to two separate MongoDB databases for different purposes..env
MongoDB connection URI for the Delta Dispatch database. Used for dispatch-related data.Configured in
src/app.module.ts:32 with connection name deltaDispatch.MongoDB connection URI for the Auth Software database. Used for user authentication and management.Configured in
src/app.module.ts:33 with connection name authSoftware.Authentication Configuration
.env
Secret key for signing and verifying JWT tokens. Used in
src/app/auth/strategies/jwt.strategy.ts:18.Security Requirements:- Minimum 32 characters
- Use cryptographically secure random string
- Never commit to version control
- Rotate periodically in production
Application Configuration
.env
HTTP server port. The application listens on this port, configured in
src/main.ts:17.Application environment. Common values:
development, production, staging.Connection String Formats
PostgreSQL Connection String
While Walle uses individual environment variables for PostgreSQL, the equivalent connection string format is:MongoDB Connection Strings
Environment-Specific Configurations
Development Environment
.env.development
Staging Environment
.env.staging
Production Environment
.env.production
In production, use environment variable substitution (
${VAR_NAME}) to inject secrets from your deployment platform (AWS Secrets Manager, Docker secrets, Kubernetes secrets, etc.).Security Best Practices
Never Commit Secrets
Never Commit Secrets
Add Commit only example files:
.env to .gitignore to prevent committing secrets:.gitignore
.env.example
Use Strong Credentials
Use Strong Credentials
PostgreSQL:
- Use strong passwords (minimum 16 characters)
- Create dedicated database users with minimal privileges
- Enable SSL/TLS for connections in production
- Enable authentication (
--auth) - Use role-based access control (RBAC)
- Enable encryption at rest and in transit
- Use minimum 256-bit secrets (32+ characters)
- Rotate secrets periodically
- Use different secrets per environment
Secure Connection Strings
Secure Connection Strings
PostgreSQL SSL:MongoDB TLS:
Network Security
Network Security
- Use VPC/private networks for database access
- Implement IP whitelisting on database servers
- Enable firewall rules to restrict access
- Use connection pooling with limits
- Monitor and log all database connections
Secret Management
Secret Management
Development:
- Use
.envfiles locally - Never share
.envfiles via chat/email
- AWS: Use AWS Secrets Manager or Parameter Store
- Docker: Use Docker secrets
- Kubernetes: Use Kubernetes secrets or external secret managers
- Azure: Use Azure Key Vault
- GCP: Use Google Secret Manager
Credential Rotation
Credential Rotation
Implement a rotation schedule:
- JWT_SECRET: Every 90 days
- Database passwords: Every 180 days
- MongoDB credentials: Every 180 days
Configuration Validation
Verify Configuration on Startup
Create a configuration validation service:src/common/config/config.validation.ts
Test Database Connections
Verify all connections are working:Troubleshooting
Environment variables not loading
Environment variables not loading
Problem: Variables defined in
.env are undefinedSolutions:- Ensure
.envfile is in project root (same directory aspackage.json) - Check file name is exactly
.env(not.env.txt) - Verify
ConfigModule.forRoot()includes correctenvFilePath - Restart the application after changing
.env - Use
console.log(process.env.VARIABLE_NAME)to debug
PostgreSQL connection refused
PostgreSQL connection refused
Problem:
ECONNREFUSED errorsSolutions:- Verify PostgreSQL is running:
pg_isready -h $POSTGRES_HOST -p $POSTGRES_PORT - Check host and port values
- Verify firewall allows connections on PostgreSQL port
- For Docker: use
host.docker.internalinstead oflocalhost
MongoDB authentication failed
MongoDB authentication failed
Problem:
MongoServerError: Authentication failedSolutions:- Verify username and password in connection URI
- Check if authentication is enabled:
mongosh --eval "db.adminCommand('getCmdLineOpts')" - Ensure user exists and has correct permissions
- Verify database name in connection string
- For Atlas: check network access IP whitelist
JWT secret too weak
JWT secret too weak
Problem: Security warnings about JWT secretSolutions:
- Generate a strong secret using crypto:
- Ensure minimum 32 characters
- Use different secrets for each environment
Next Steps
Partition Management
Learn how to manage database partitions
Setup Guide
Complete installation and setup process
Authentication
Configure JWT authentication
API Reference
Explore the API endpoints