DEV Community

Alex Gutscher
Alex Gutscher

Posted on

๐Ÿ“ธ Meet env-snapper: Snapshot & Track Your .env Files with Ease

Have you ever spent way too long debugging a broken app, only to realize your .env file silently changed?
Yeahโ€ฆ me too.

Thatโ€™s why I built env-snapper โ€” a simple CLI tool to help developers take snapshots of their .env files and compare them over time.

๐Ÿง  Why I built it
Environment variables are essential for modern apps, but they're also fragile.

One typo, one missing variable, or an accidental overwrite โ€” and suddenly your app doesnโ€™t work, or worse, it's working weirdly.

If youโ€™re working across different machines, teams, or environments, tracking what changed (and when) in your .env can be a headache.

So I thought: โ€œWhy not just snapshot it and compare later?โ€

โš™๏ธ What env-snapper does
Hereโ€™s what it brings to the table:

โœ… Snapshot your current .env file

โœ… Automatically timestamp and version each snapshot

โœ… Diff between snapshots to spot changes

โœ… CLI interface (easy to use via npx)

โœ… No dependencies on external services โ€” local and fast

๐Ÿ› ๏ธ How to use it

npm install -g env-snap

## Initialize env-snap in your project
npx env-snap init

# Manually snapshot current .env
npx env-snap snapshot

# List all snapshots
npx env-snap list

# Revert to a previous snapshot
npx env-snap revert <snapshot-id>

# Show diff between snapshots or with current .env
npx env-snap diff <snapshot-id>            # Compare with previous snapshot
npx env-snap diff <snapshot-id> --current  # Compare with current .env

# Watch .env for changes and snapshot automatically
npx env-snap watch

# Add a description to a snapshot (after creation)
npx env-snap desc <snapshot-id> "Your description here"

# Example: create a snapshot with a description
npx env-snap snapshot --desc "Added Sentry config and removed Stripe keys"

# Prune old snapshots, keeping only the latest 5 (default)
npx env-snap prune

# Prune and keep only the latest N snapshots (e.g., 10)
npx env-snap prune 10

# Preview changes before restoring a snapshot
npx env-snap preview <snapshot-id>
Enter fullscreen mode Exit fullscreen mode

You'll see a clean, side-by-side diff of what changed between your last two snapshots.

๐Ÿ’ก Use cases
๐Ÿงช Testing config changes between deployments

๐Ÿ‘ฏ Collaborating across teams with different environments

๐Ÿ› ๏ธ Debugging issues caused by subtle .env tweaks

๐Ÿงณ Moving between machines without losing setup details

๐Ÿ“ฆ Get it now
You can check out the package here:
๐Ÿ‘‰ https://www.npmjs.com/package/env-snapper

The code is open source and Iโ€™d love your feedback, feature requests, or PRs!

๐Ÿ’ฌ Letโ€™s connect!
Got questions, ideas, or bugs? Drop a comment below or reach out on X/Twitter [@HustleStacked].
Letโ€™s keep our environments sane. ๐Ÿ˜„

Top comments (0)