Recipes
Learn how to parse different types of environment variables in different runtimes.
envin
leverages the full power of all supported schema validators, allowing you to use transforms, default values, and other advanced features to create powerful and flexible validation schemas for your environment variables. Below are several example recipes for common use cases.
All environment variables are strings, so ensure that the first validator is
for strings (e.g. for zod
is z.string()
). This will be enforced at the
type level in the future.
Booleans
Coercing booleans from strings is a common use case. Below are two examples of how to accomplish this, though you can implement any coercion logic that suits your needs.
Default primitive coercion should not be used for booleans, since every
non-empty string gets coerced to true
.
Numbers
Converting numbers from strings is another common use case that requires careful handling.
Storybook
Storybook uses its own bundler that is unaware of envin and doesn't call env
to validate environment variables. You can use Storybook's built-in support for environment variables to ensure all required variables are available in your Storybook environment: