env-type-gen-cli
v1.0.0
Published
Automatically generate TypeScript types (env.d.ts) from your .env file with watch mode.
Maintainers
Readme
env-type-gen-cli
Automatically generate TypeScript declarations (env.d.ts) for your environment variables from .env files. Keep your process.env type-safe without manual overhead.
Features
- 🚀 Auto-inference: Infers
boolean,number, andstringtypes. - 👀 Watch Mode: Updates your types automatically as you edit your
.envfile. - ⚡ Zero Dependencies: Blazingly fast and no package bloat.
- 🛠️ Custom Output: Specify custom input and output paths.
Installation
npm install -g env-type-gen-cli
# OR
npm install --save-dev env-type-gen-cliUsage
Simple Usage
Run in your project root:
npx env-type-gen-cliThis generates an env.d.ts file from your .env.
Watch Mode
Keep your types in sync automatically:
npx env-type-gen-cli --watchCustom Path
If your env file is not named .env:
npx env-type-gen-cli .env.local --out types/env.d.tsGenerated Output Example
For a .env like:
PORT=3000
DEBUG=true
DB_URL=mongodb://localhost:27017It generates:
declare namespace NodeJS {
interface ProcessEnv {
PORT: number | string;
DEBUG: boolean | string;
DB_URL: string;
}
}License
MIT
