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 init
pnx @arkenv/cli@latest init
yarn dlx @arkenv/cli@latest init
bunx @arkenv/cli@latest init

Your schema

Your env.ts file is where the ✨magic✨ happens – variables referenced from this object are guaranteed to match the schema defined here.

env.ts
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:

.env
LOG_LEVEL=info
API_KEY=secret
ALLOWED_ORIGINS=http://localhost:3000,https://example.com

We recommend not committing the .env file to version control.

Using environment variables

You can now import the validated, typesafe env object anywhere in your codebase.

database.ts
import {  } from './env';

const  = {
  : .,
  : .,
  : . === 'development'
};

.(`Connecting to ${.}:${.}...`);

Next steps