ark.env

What is ark.env?

ark.env is a powerful TypeScript-first environment variable management library that provides runtime validation and typesafety for your application's configuration.

#Key features

  • 🔒 Typesafe: Full TypeScript support with precise type inference
  • 🚀 Runtime validation: Catch missing or invalid environment variables early in development
  • 💪 Powered by ArkType: Built on top of ArkType's powerful type system
  • 🪶 Lightweight: Only a single dependency (5.6 kB)
  • Fast: Optimized for performance with minimal overhead

#Why ark.env?

Managing environment variables in TypeScript applications can be error-prone. Common issues include:

  • Missing environment variables causing runtime crashes
  • Type mismatches between expected and actual values
  • Lack of validation for critical configuration
  • No autocomplete or type hints in your IDE

ark.env solves these problems by providing a typesafe, validated way to define and use environment variables in your TypeScript applications.

#Quick example

Here's the kind of code you can expect when using ark.env:

example.ts
import ark, { host, port } from 'ark.env';
 
const env = ark.env({
  HOST: host,           // Validates IP address or localhost
  PORT: port,           // Ensures valid port number (0-65535)
  NODE_ENV: "'development' | 'production' | 'test'",
});
 
// TypeScript knows the exact types!
console.log(env.HOST);     // string
console.log(env.PORT);     // number
console.log(env.NODE_ENV); // "development" | "production" | "test"

#Next steps

On this page