Getting started
Compatibility
ArkEnv is tested on Next.js 16.x, Node.js LTS and Current, Vite from 4.x to 8.x, and Bun 1.3.x. Older versions may work but are not officially supported.
Installation
The easiest way to get started is with the ArkEnv CLI. It automatically configures ArkEnv for your project, installs dependencies, and scaffolds your initial schema.
npx @arkenv/cli@latest initpnx @arkenv/cli@latest inityarn dlx @arkenv/cli@latest initbunx @arkenv/cli@latest initYour schema
Your env.ts file is where the ✨magic✨ happens – variables referenced from this object are guaranteed to match the schema defined here.
import , { } from 'arkenv';
export const = ({
// Automatic inference for simple literals
: "'development' | 'production' | 'test' = 'development'",
// Database configuration
: "string.host",
: "number.port = 5432",
// Complex types and arrays via ArkType
: ("string[]").(() => ["localhost"]),
// Optional environment variable
"API_KEY?": 'string'
});Loading environment variables
Environment variables can be loaded in different ways, but the most common approach is to use a .env file at the root of your project:
LOG_LEVEL=info
API_KEY=secret
ALLOWED_ORIGINS=http://localhost:3000,https://example.comWe recommend not committing the
.envfile to version control.
Using environment variables
You can now import the validated, typesafe env object anywhere in your codebase.
import { } from './env';
const = {
: .,
: .,
: . === 'development'
};
.(`Connecting to ${.}:${.}...`);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