@envra/core
v0.1.2
Published
Define, validate, and safely consume runtime configuration in TypeScript
Maintainers
Readme
@envra/core
Define, validate, and safely consume environment variables in TypeScript — schema, inferred types, secret masking, and helpers for docs / .env.example / doctor.
Install
pnpm add @envra/core
# or
npm install @envra/coreQuick example
import { defineEnv, str, url, int, bool, secret, oneOf } from "@envra/core";
export const env = defineEnv({
NODE_ENV: oneOf(["development", "test", "production"] as const),
APP_URL: url(),
DB_URL: secret(url()).serverOnly(),
PORT: int().default(3000),
REDIS_ENABLED: bool().default(false),
});Use env.values, env.get, env.has, and env.meta. See the full documentation on GitHub.
NestJS / Record<string, unknown>
@nestjs/config passes a plain object into validate. Use unknownRecordToEnvSource so nested values become JSON strings instead of [object Object]:
import { defineEnv, unknownRecordToEnvSource } from "@envra/core";
return defineEnv(schema, { source: unknownRecordToEnvSource(config) }).values;runDoctor
runDoctor({ schema, env, profile, undeclaredPolicy?: 'all' | 'ignore-system' | 'loaded-only', loadedEnvKeys? }) — use ignore-system on developer machines to avoid hundreds of UNDECLARED_ENV warnings from OS/shell keys.
CLI
For check, sync, docs, and doctor, add @envra/cli as a dev dependency.
License
MIT — see LICENSE in the monorepo.
