Env Configuration
Environment variables are a critical part of any production application. They allow you to configure your application based on the environment it's running in (development, testing, production).
Installation Guide
Install the component using the servercn CLI:
npx servercn-cli add env-configBasic 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.