Quickstart
Let's get you started with a few simple steps.
Configure your project
Enable strict mode for the best typesafety, and use a modern TypeScript module resolution:
{
"compilerOptions": {
"strict": true,
"moduleResolution": "bundler" // or "node16" / "nodenext"
}
}You may omit
moduleResolutionifmoduleis"Preserve","Node16", or"NodeNext". See Requirements for details.
ArkType users: follow the ArkType setup to complete your configuration.
Define the schema
Add a schema to make your environment variables validated and typesafe.
We're using ArkType for this example, but you can mix and match any Standard Schema validator.
import from 'arkenv';
import { } from 'arkenv/arktype';
export const = ({
// Optional variables with defaults
: "'debug' | 'info' | 'warn' | 'error' = 'info'",
// Arrays (comma-separated by default)
: ("string[]").(() => ["localhost"]),
: ("string[]").(() => []),
// Optional environment variable
"API_KEY?": 'string'
});Define environment variables
Define some environment variables in a .env file in your project root:
LOG_LEVEL=info
API_KEY=secret
ALLOWED_ORIGINS=http://localhost:3000,https://example.comWe recommend not committing the
.envfile to version control.
Use in your code
Import and use your validated and typed environment variables!
import { } from './config/env';
// Hover to see your validated config
const = {
: .,
: .,
};Next steps
Standard Schema Validators
Use Zod, Valibot, or any Standard Schema validator with ArkEnv
IDE Integrations
Get syntax highlighting, ErrorLens, and more for VS Code
Examples
Dive into ArkEnv with our collection of examples
How to load environment variables
Learn environment variables management in different environments and deployment scenarios