The podverse-management-api application requires environment variable validation on startup. All environment variables must be provided through the .env file.
Validation occurs in src/lib/startup/validation.ts during application startup. The validation:
- Checks if each variable is set
- Validates format/type where applicable (e.g., UUID for JWT secret, numeric for ports)
- Displays a categorized status for each variable
- Aborts startup if any required variables are missing or invalid
-
AUTH_JWT_SECRET(Required)- Must be a valid UUID
- Used for JWT token generation
- Example:
123e4567-e89b-12d3-a456-426614174000 - Generate with:
uuidgen(macOS/Linux) or use an online UUID generator
-
USER_AGENT(Required)- Format:
BrandName Bot Environment/AppName/Version - Must include "Bot" in the first part (before the first slash)
- Example:
Podverse Bot Local/Management-API/5 - Used for external API requests
- Format:
DB_HOST(Required) - Database hostnameDB_PORT(Required) - Database port (must be a valid number)DB_READ_USERNAME(Required) - Read-only database usernameDB_READ_PASSWORD(Required) - Read-only database passwordDB_READ_WRITE_USERNAME(Required) - Read-write database usernameDB_READ_WRITE_PASSWORD(Required) - Read-write database passwordDB_DATABASE(Required) - Database nameDB_SSL_CONNECTION(Optional) - Use SSL for database connection (default:false)
API_PORT(Required) - API server port (must be a valid number)API_PREFIX(Required) - API route prefix (e.g.,/api)API_VERSION(Required) - API version (e.g.,v2)COOKIE_DOMAIN(Required) - Domain for cookiesAPI_ALLOWED_CORS_ORIGINS(Required) - Comma-separated list of allowed CORS origins (must contain at least one origin)
WEB_PROTOCOL(Required) - Web protocol (httporhttps)WEB_DOMAIN(Required) - Web domain (e.g.,localhost:3999ormanagement.podverse.fm)
NODE_ENV(Optional) - Node environment (development,production, etc.)LOG_LEVEL(Optional) - Logging level (error,warn,info,debug,verbose,silly,silent)
Variables containing PORT are automatically validated to ensure they are valid positive numbers:
DB_PORTAPI_PORT
- UUID Format:
AUTH_JWT_SECRETmust be a valid UUID - User-Agent Format:
USER_AGENTmust followBrandName Bot Environment/AppName/Versionand include "Bot" in the first part - CORS Origins:
API_ALLOWED_CORS_ORIGINSmust contain at least one origin (comma-separated)
During startup, the validation displays:
- A categorized list of all environment variables
- Status indicator (✓ for valid, ✗ for invalid)
- Whether the variable is required or optional
- A message indicating the validation result
- A summary with totals and counts
Example output:
=== Environment Variable Validation ===
[Auth & Security]
✓ AUTH_JWT_SECRET - Valid UUID
✓ USER_AGENT - Valid format
[Database]
✓ DB_HOST - Set
✓ DB_PORT - Set
...
=== Validation Summary ===
Total: 18
Passed: 18
Failed: 0
Required Missing: 0
- Startup abort: If any required variable is missing or invalid, the application will abort startup with a clear error message.
- Validation file: See
src/lib/startup/validation.tsfor the complete validation implementation.
When adding a new environment variable to the application:
-
Add to
src/config/index.ts:- Add the variable to the appropriate config section
-
Add validation to
src/lib/startup/validation.ts:- Determine if the variable is required or optional
- Add appropriate validation call in
validateAllEnvironmentVariables() - Use
validateRequired()for required vars - Use
validateOptional()for optional vars - Add custom validation if format/type checking is needed
-
Update this file:
- Add the variable to the appropriate section above
- Document any special requirements (format, type)
-
Update
.env.example(if applicable):- Add the variable with a comment explaining its purpose