What is ArkEnv
Link to section: introductionIntroduction
Tip
📖 Reading this on GitHub? Check out this page in our docs to hover over code blocks and get type hints!
ArkEnv is an environment variable parser powered by ArkType, TypeScript's 1:1 validator. ArkEnv lets you use familiar TypeScript-like syntax to create a ready to use, typesafe environment variable object:
import arkenv from 'arkenv';
const = arkenv({
HOST: "string.host", // valid IP address or localhost
PORT: "number.port", // valid port number (0-65535)
NODE_ENV: "'development' | 'production' | 'test'",
});
// Hover to see ✨exact✨ types
const = .HOST;
const = .PORT;
const = .NODE_ENV;With ArkEnv, your environment variables are guaranteed to match your schema. If any variable is incorrect or missing, the app won't start and a clear error will be thrown:
ArkEnvError: Errors found while validating environment variables
HOST must be a string or "localhost" (was missing)
PORT must be an integer between 0 and 65535 (was "hello")Link to section: featuresFeatures
- Zero external dependencies
- Works in Node.js, Bun, and Vite
- Tiny: <1kB gzipped
- Build-time and runtime validation
- Single import, zero config for most projects
- Validated, defaultable, typesafe environment variables
- Powered by ArkType, TypeScript's 1:1 validator
- Compatible with any Standard Schema validator (Zod, Valibot, etc.)
- Optimized from editor to runtime
Link to section: the-arkenv-iconThe ArkEnv icon
The ArkEnv icon tells the story of what we're building. It weaves together three distinct symbols:
- A gear: At first glance, it's a settings gear, representing the core mechanical purpose of the library: precise environment configuration.
- A ship's wheel: Look closer, and it's a ship's wheel. This honors the Ark motif, symbolizing the freedom to explore and build, steered by reliable technology.
- A lighthouse: It is also the Japanese map symbol for a lighthouse. Just as a lighthouse warns sailors of danger, ArkEnv's typesafety guides your apps away from the rocky shores of runtime errors.