Env Configuration
Setup type-safe environment variables with Zod and Dotenv.
Installation Guide
Install the component using the servercn CLI:
npx servercn-cli@latest add env-config Basic Implementation
Usage
You can now import the env object anywhere in your application and get full type safety and auto-completion.
Why Zod?
Using Zod for environment validation provides several benefits:
- Validation: It ensures that environment variables like PORT are actually strings/numbers as expected.
- Transformation: You can transform strings into other types (e.g., parsing a string to a boolean or number).
- Error Reporting: If an environment variable is missing or wrong, Zod provides detailed error messages.