Skip to main content

๐Ÿ—๏ธ 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โ€‹

  1. Scans your existing .env files (if any).
  2. Prompts you to add environment variables interactively.
  3. Asks for the expected data type of each variable (string, number, or boolean).
  4. Generates a new .env.schema.json file (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โ€‹

FlagDescriptionExample
--output <path>Specify a custom location for the generated schema fileenv-checkup init --output ./config/env.schema.json
--overwriteForce overwrite if .env.schema.json already existsenv-checkup init --overwrite
--yesSkip prompts and generate schema automatically from existing .env filesenv-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โ€‹

CommandDescription
npx env-checkup initStart interactive schema creation
--output <path>Save schema to a custom path
--overwriteReplace existing schema file
--yesGenerate automatically without prompts

Next: โ†’ validate Command