๐๏ธ env-checkup init
The init command helps you quickly generate a schema file that defines all the environment variables required in your project.
This schema file is later used by the validate command to ensure consistency and correctness in your .env files.
๐งฉ Usageโ
Run the following command in your project root:
npx env-checkup init
๐ช What It Doesโ
- Scans your existing
.envfiles (if any). - Prompts you to add environment variables interactively.
- Asks for the expected data type of each variable (
string,number, orboolean). - Generates a new
.env.schema.jsonfile (or updates an existing one).
๐ฌ Example Interactive Sessionโ
$ npx env-checkup init
? Enter variable name: DATABASE_URL
? Type of value (string/number/boolean): string
? Enter variable name: PORT
? Type of value: number
? Enter variable name: JWT_SECRET
? Type of value: string
? Add another variable? (y/n): n
โ Schema file generated successfully at ./.env.schema.json
๐ Output Fileโ
Once complete, Env Checkup creates a file named .env.schema.json in your project root.
Example:
{
"DATABASE_URL": "string",
"PORT": "number",
"JWT_SECRET": "string"
}
This schema acts as the source of truth for what variables are expected in your .env files.
โ๏ธ Optionsโ
| Flag | Description | Example |
|---|---|---|
--output <path> | Specify a custom location for the generated schema file | env-checkup init --output ./config/env.schema.json |
--overwrite | Force overwrite if .env.schema.json already exists | env-checkup init --overwrite |
--yes | Skip prompts and generate schema automatically from existing .env files | env-checkup init --yes |
๐ง Example with Optionsโ
Generate schema to a custom directory:โ
npx env-checkup init --output ./config/env.schema.json
Overwrite existing schema file:โ
npx env-checkup init --overwrite
Automatically detect variables (non-interactive mode):โ
npx env-checkup init --yes
Env Checkup will look for .env files, read all key names, and infer types automatically where possible.
๐งพ Example Project Structureโ
my-app/
โฃ .env
โฃ .env.local
โฃ .env.schema.json
โฃ envcheckup.config.json
โฃ package.json
โ src/
โ index.ts
๐งฉ Example .env Fileโ
PORT=4000
DATABASE_URL=postgres://localhost:5432/mydb
JWT_SECRET=supersecretkey
DEBUG=true
After running env-checkup init, you get:
{
"PORT": "number",
"DATABASE_URL": "string",
"JWT_SECRET": "string",
"DEBUG": "boolean"
}
๐งญ Tipsโ
โ
Always commit .env.schema.json to version control
๐ซ Never commit .env or .env.local files
๐งช Re-run env-checkup init whenever new environment variables are introduced
๐ Use --overwrite when regenerating schema intentionally
๐งฐ Example npm Scriptโ
To make schema generation easier for your team, add this script to your package.json:
"scripts": {
"env:init": "env-checkup init"
}
Then run:
npm run env:init
๐งพ Summaryโ
| Command | Description |
|---|---|
npx env-checkup init | Start interactive schema creation |
--output <path> | Save schema to a custom path |
--overwrite | Replace existing schema file |
--yes | Generate automatically without prompts |
Next: โ validate Command