How to reuse your schema
Define your schema once and reuse it across your application.
ArkEnv supports both raw schema objects and type definitions created with ArkType's type() function. Use type definitions when you need to validate the same environment variables in multiple places.
Recall that with ArkEnv, defining your schema is done at the same time as you parse the environment variables:
import from 'arkenv';
const = ({
: "string.host",
: "number.port",
: "boolean",
});But what if you wanted to share this schema across your app and validate+parse it against different environments?
This might sound like a niche use-case, but it comes up more often than you'd think - especially with tools like Vite, Next.js, or Bun, where multiple runtimes might need access to the same environment variables. Even in something as simple as a Vite+React setup, you might want your .env schema available both inside your vite.config.ts (Node.js) and in client code (Vite dev server). See the Node.js example for a basic setup, or the Vite playground for a complete multi-runtime configuration.
That's where type definitions start making sense: define your schema once with type(), and reuse it wherever you need.
import from 'arkenv';
import { } from 'arkenv/arktype';
const = ({
: "string.host",
: "number.port",
: "boolean",
});
// Use it in multiple places with full type inference
const = (, { : . });
const = (, {
: { : "localhost", : "3000", : "true" },
});
// TypeScript knows the exact types
const = .;
const = .;