Loading page content…
How I designed and shipped a privacy-conscious TypeScript CLI that compares .env.example with .env, reports missing keys and returns CI-friendly exit codes.

Environment variables are easy to overlook because they usually sit outside the main application code. A project may compile correctly and still fail at runtime because one required variable was never added to the local or deployed environment.
I built EnvGuard to make that failure visible earlier. It is a lightweight command-line tool that compares the variable names declared in .env.example with those present in .env, then produces a readable report showing what was found and what is missing.
The goal was not to build a complete configuration platform. It was to solve one narrow problem well: help developers identify incomplete environment configuration before it becomes a runtime error.
An .env.example file communicates the configuration a project expects, while .env contains the developer’s actual local configuration. As projects grow, the two files can quietly move out of sync.
A newly added API key may exist on one developer’s machine but be absent from another. A deployment may be missing a service URL. Onboarding instructions may mention a variable that was later renamed. These mistakes are simple, but they can consume unnecessary debugging time because the visible error often appears far away from the real cause.
Configuration mistakes should fail early, clearly and without exposing the secrets they are checking.
That principle became the boundary for EnvGuard: compare variable names, communicate the result clearly and avoid printing environment-variable values.
For the first release, I deliberately kept the scope small. EnvGuard checks one configuration relationship:
.env.example → .env
This limited scope made the tool easier to reason about, test and release. It also left a clear boundary between what EnvGuard supports today and what could be added later.
Architecture
01 / Parse
Extract variable names, line numbers and safe diagnostics while handling comments, export syntax, duplicates and different line endings.
02 / Validate
Compare the expected names with the configured names and produce a structured result containing found and missing variables.
03 / Report
Turn the validation result into a responsive terminal report with clear statuses, summaries and actionable error messages.
Environment files can contain sensitive credentials, so the parser was designed around variable names rather than secret values. It records whether a declaration has a value, but it does not preserve that value in the parsed result.
When EnvGuard reports a malformed line containing an equals sign, everything after the equals sign is replaced with a mask. This allows the tool to explain where the syntax problem occurred without printing the original value.
function sanitizeRawLine(line: string): string { const equalIndex = line.indexOf("=");
if (equalIndex === -1) { return line; }
const prefix = line.slice(0, equalIndex + 1); return `${prefix}***`;}The parser handles comments, blank lines, Windows CRLF line endings, quoted values and values containing additional equals signs. It also supports declarations prefixed with export and records duplicate names without treating repeated declarations as separate requirements.
Variable names are validated using the familiar environment-variable identifier pattern: a letter or underscore followed by letters, numbers or underscores.
const IDENTIFIER_REGEX = /^[A-Za-z_][A-Za-z0-9_]*$/;EnvGuard currently validates presence rather than value correctness. If a name appears in .env, the first release considers that variable present even when its value is empty.
The internal model already records whether a target variable contains a non-empty value, but that information is not yet used to fail validation. Keeping that distinction explicit avoids presenting the current release as more capable than it is.
Current boundaries
Supported
EnvGuard identifies names declared in .env.example that are absent from .env and reports them as missing.
Not yet
The current release does not require non-empty values or validate formats such as URLs, numbers, booleans or tokens.
Not yet
The current release does not automatically inspect .env.local, environment-specific files or custom paths.
A command-line tool still needs a considered interface. EnvGuard uses colour, alignment and short status labels to make the report scannable without turning it into a wall of debug output.
The report adapts to the available terminal width, truncates exceptionally long names when necessary and presents a summary of found, missing and total variables. Errors such as missing files and unknown commands use the same visual language as the main report.
◆ ENVGUARD
CONFIGURATION · .env.example → .env
✓ DATABASE_URL FOUND✓ API_KEY FOUND✗ JWT_SECRET MISSING
2 found · 1 missing · 3 totalThe exit code is part of EnvGuard’s public behaviour. A successful validation returns 0. Missing variables, unreadable required files and invalid commands return 1.
This means the same command can be used interactively by a developer or added to an automated workflow that should stop when required configuration is incomplete.
{ "scripts": { "check:env": "envguard check" }}The codebase contains parser, validator and CLI tests. The test cases cover valid declarations, blank files, comments, export syntax, duplicate variables, empty values, invalid identifiers, quoted values, Unicode values and Windows line endings.
The CLI tests also exercise successful checks, missing variables, missing files, help output, version output, unknown commands, syntax warnings and execution of the built command-line binary.
The important security assertion is repeated in the parser and CLI tests: malformed input may be reported, but its value must not appear in the result.
At the current stage, the repository contains 35 test cases across the parser, validator and CLI suites.
EnvGuard is published publicly on npm as @itseghosime/envguard. The package is scoped to my npm identity, while the executable developers type in the terminal remains envguard.
That distinction matters because similarly named unscoped packages already exist. Clear installation documentation helps developers install the correct package instead of assuming the npm package and terminal command must have identical names.
npm install --save-dev @itseghosime/envguardnpx envguard checkThe source code is available on GitHub, and the published package is available through npm.
EnvGuard is currently at version 0.1.1. The initial command-line workflow is released, documented and available for use, while the most recent update focused on correcting package installation guidance and improving troubleshooting.
The next stage is not about making the interface larger for its own sake. It is about carefully expanding the kinds of projects EnvGuard can support while keeping its behaviour predictable.
These are future directions rather than features in the current release.
Building EnvGuard reinforced that useful developer tools do not have to begin with a large feature set. A narrow contract, clear failure behaviour and thoughtful reporting can make a small utility genuinely useful.
It also showed me that security is not only about encryption or authentication. In developer tooling, it can be as practical as deciding which data should never be stored, returned or printed.
The project is intentionally small, but it brings together CLI design, parsing, validation, testing, package publishing and documentation in one complete release workflow.
The best configuration error is the one a developer finds before the application starts.
Working note / open conversation
These notes are working documents. If you see another angle or want to discuss the implementation, I would like to hear it.
Related notes
Note 02 · Architecture
How SabiWork took me from artisan search into shared workflow states, server-side payment rules and reviewing AI-assisted changes as a team.
Note 03 · Architecture
How building Nia taught me to separate search, property data and conversation logic, and to give renters control over voice input.