fatima

Generated SDK from .env

Generate private and public SDK files from dotenv input.

Use this flow when .env remains the source of local development variables but application code should import a generated SDK.

Configure file output

{
  "generator": "typescript",
  "file": "src/env.ts",
  "environment": "{env:NODE_ENV} ?? 'development'",
  "publicPrefix": "PUBLIC_",
  "providers": {
    "development": [{ "provider": "file", "file": ".env" }]
  },
  "model": {
    "PORT": "integer",
    "DATABASE_URL": "url",
    "PUBLIC_BASE_URL": "url"
  }
}

Generate the files:

fatima generate --strict

Fatima writes:

  • src/env.ts, containing private runtime access;
  • src/env.public.ts, containing only keys that start with PUBLIC_.

Server-side import

import { env } from "./env";

console.log(env.DATABASE_URL);

Client-safe import

import { publicEnv } from "./env.public";

console.log(publicEnv.PUBLIC_BASE_URL);

Do not import the private SDK into browser code. Use the generated public file for public values.