Skip to main content

Getting Started

Install​

npm install tiny-typed-env

Node 18+ is required.

Quick usage (Node / Bun)​

import { createEnv, s } from "tiny-typed-env/node";

export const schema = {
DATABASE_URL: s.url(),
PORT: s.port({ default: 3000 }),
NODE_ENV: s.enum(["development", "test", "production"], {
default: "development",
}),
DEBUG: s.boolean({ default: false }),
API_KEY: s.string({ min: 8 }),
};

export const env = createEnv(schema);

env.PORT; // number
env.DATABASE_URL; // string

createEnv loads .env files, then validates. If a variable is missing or invalid, the process fails at boot:

Invalid environment variables:

DATABASE_URL: Expected a valid URL
API_KEY: Must be at least 8 characters

Fix your .env file or the host environment, then restart.

Secret-looking keys (API_KEY, TOKEN, *_KEY, …) never print the raw value—only the failure reason.

CLI​

Export schema (as above), then:

npx tiny-typed-env check # validate env, exit 1 on failure
npx tiny-typed-env example # write .env.example from schema
npx tiny-typed-env example --print # print to stdout

See CLI for options and discovery rules.

Choose your entrypoint​

ImportUse when
tiny-typed-env/nodeNode or Bun — loads .env files for you
tiny-typed-envDeno, Workers, browsers — pass runtimeEnv yourself

Next​