snaps-back
v0.0.1
Published
CLI to snapshot and restore .env files
Downloads
10
Maintainers
Readme
env-snaps
Snapshot and restore project .env files. Simple, fast, and
minimal.
Package name:
snaps-backCommand:env-snapsandsnaps-backThis package installs two CLI commands namedenv-snapsandsnaps-back. Both run the same tool — use whichever name you prefer.
Why this exists
- When you work on a project, your
.envfile (secrets and configs) changes between dev, staging, prod, etc. - Manually copying/renaming
.envgets messy and error-prone. - env-snaps saves snapshots of your
.envto files like.env.dev.snapand lets you quickly load them back.
You are never forced to learn a complex system---these are just plain text files in your repo folder.
Install
Local (recommended):
npm install --save-dev snaps-backThis gives you npx env-snaps ... inside your project.
Global (optional):
npm install --global snaps-backThen you can run env-snaps ... anywhere.
Snapshots (what & where)
- A snapshot is a plain file:
.env.<name>.snapin your chosen directory. - By default, snapshots live in your project root (same folder as
.env). - You can override the directory via:
- global flag
--dir <path>, or - environment variable
ENV_SNAPS_DIR.
- global flag
Examples:
.env.dev.snap
.env.staging.snap
.env.prod.snapCommands & Flags
Global options
-d, --dir <path>: Directory to read/write.envand snapshots
(Tip: can also setENV_SNAPS_DIRto avoid repeating the flag)
save <name>
Save the current .env to .env.<name>.snap.
Options: - -f, --force: Overwrite the snapshot if it already exists.
Example (works with either command)
npx env-snaps save dev
or
npx snaps-back save dev
More examples:
# Save current .env as .env.dev.snap
npx env-snaps save dev
# Overwrite if exists
npx env-snaps save dev --forceload <name>
Load .env.<name>.snap into .env.
Options: - --backup: If a .env exists, first back it up to
.env.backup.
Example:
# Load .env.dev.snap into .env
npx env-snaps load dev
# Backup existing .env -> .env.backup before loading
npx env-snaps load dev --backuplist
List all available .env.*.snap files.
Example:
npx env-snaps listdiff <name1> <name2>
Show a line-by-line diff between two snapshots.
Options: - --color (default) / --no-color
Example:
# Compare dev vs staging
npx env-snaps diff dev staging
# Force no color (useful for CI or logs)
npx env-snaps diff dev staging --no-colorWindows notes
- Works fine in PowerShell and CMD.
- If you pass numbers to any flags in the future, prefer
parseInt(value, 10)in your own scripts to avoid octal parsing surprises.
(This CLI doesn't parse numbers itself, but it's good practice.)
Minimal dependencies
Examples
# Save snapshots for multiple environments
npx env-snaps save dev
npx env-snaps save staging
npx env-snaps save prod
# Switch to dev quickly (backup current .env first)
npx env-snaps load dev --backup
# List what you have
npx env-snaps list
# See what changed between dev and staging
npx env-snaps diff dev stagingFAQ
Where are the files stored?
Right alongside your .env by default (or in the folder you pass via
--dir / ENV_SNAPS_DIR).
Is it safe to commit snapshots?
Treat them like your .env --- if they contain secrets, do not
commit them. Use .gitignore if needed.
Does the tool merge .env files?
No. It's intentionally minimal: it saves, loads, lists, and diffs.
