@cldmv/envm is a modern, cross-platform environment variable manager for Node.js projects. Designed for both developers and automation, it lets you safely read, write, and manipulate environment variables on Windows and POSIX systems—without ever touching a class. With robust backup and restore features, a powerful CLI, and a clean, ESM-first API, envm makes managing your environment variables simple, safe, and scriptable. Whether you're tweaking your PATH, rolling back a bad change, or automating setup across platforms, envm gives you the control and confidence you need.
require()returnsenvManageritself —require("@cldmv/envm").set(…)works, and.envManager,.defaultandconst { envManager } = require(…)all point at the same object, so v1.1.0 code keeps working (#87, #89).dist/is now one file per module instead of a bundle, and the CLI no longer ships its own copy of the library (#97).- Bug fixes — an unknown or missing scope is refused instead of silently doing nothing, or writing system scope on Windows (#94). The CLI no longer stores a
--flagas a value or edits the wrong variable when--nameis left out (#94), andbackup.purge()deletes backups older thanmaxAgeDays(#93). - View full v1.2.0 Changelog
- v1.1.0 (November 2026) — the CLDMV library layout with a
require()entry, type declarations and theenvm-devcondition, plus fixes for the installedenvmcommand, Windows rollback and user scope on Linux and macOS (#59, #60, #61, #62, #68, #69) (Changelog) - v1.0.12 (October 2026) —
@cldmv/vitest-runner1.5.3,vitestand@vitest/coverage-v85.0.3; dev-only, no library or CLI code changed (#42, #43, #44) (Changelog) - v1.0.11 (October 2026) —
@cldmv/fix-headers2.2.0 and@cldmv/configs1.2.4; every header already matched, so nothing was restamped (#34, #40) (Changelog) - v1.0.10 (October 2026) — the CI
✅ Required PR Checkmirror job runs on every path instead of being skipped on in-repo PRs (#32) (Changelog)
📚 For complete version history, see docs/changelog/ and the GitHub Releases.
- Cross-platform: Works on Windows (registry) and POSIX (dotfiles, /etc/environment)
- No classes: API is plain objects and functions
- ESM and CommonJS: an ESM build, plus a
require()entry that loads the same build (no second copy) - PATH-like helpers: Manipulate PATH and similar variables safely
- Backup/restore: Automatic, timestamped backups with purge and rollback
- CLI: Powerful
envmcommand for scripting and automation - TypeScript-friendly: JSDoc-annotated API with generated type declarations
- Lightweight: about 15 KB minified (core + CLI)
npm install @cldmv/envmRequires Node.js 14.14.0 or later for import. require() needs Node.js ^20.19.0 or >=22.13.0.
Developing this package needs Node.js 22.22.0 or later (devEngines).
import { envManager } from "@cldmv/envm";
// Get a variable (expanded)
const value = await envManager.getExpanded("PATH", { scope: "user" });
// Set a variable
await envManager.set("MY_VAR", "value", { scope: "user" });
// Unset a variable
await envManager.unset("MY_VAR", { scope: "user" });
// PATH helpers
await envManager.path.prepend({ name: "PATH", scope: "user", values: ["/usr/local/bin"] });
await envManager.path.append({ name: "PATH", scope: "user", values: ["/opt/bin"] });
await envManager.path.remove({ name: "PATH", scope: "user", values: ["/opt/bin"] });
await envManager.path.sort({ name: "PATH", scope: "user" });
await envManager.path.unique({ name: "PATH", scope: "user" });
// Backup helpers
await envManager.backup.list({ scope: "user" });
await envManager.backup.restore("user-PATH-2025-08-11T12-00-00-000Z.bak");
await envManager.backup.purge({ maxPerScope: 10, maxAgeDays: 7 });require() returns the envManager object itself, the same one import { envManager } gives you:
const envManager = require("@cldmv/envm");
await envManager.set("MY_VAR", "value", { scope: "user" });const { envManager } = require("@cldmv/envm") and require("@cldmv/envm").default work too; both point at the same object.
The CommonJS entry loads the ESM build through Node's require(esm). On a Node.js version without it, require() throws ERR_REQUIRE_ESM with the supported range; use import() there instead.
npx envm get --name PATH --scope user
npx envm set --name MY_VAR --value hello --scope user
npx envm unset --name MY_VAR --scope user
npx envm path prepend --name PATH --values /usr/local/bin --scope user
npx envm backup list --scope user
npx envm backup restore user-PATH-2025-08-11T12-00-00-000Z.bak
npx envm --version--name/-n— Variable name--value/-v— Value to set--scope—session,user, orsystem--raw— Get raw value (no expansion)--expanded— Get expanded value--backup— Enable/disable backup (default: true)--verify— Enable/disable verification (default: true)--dry-run— Simulate changes
prepend,append,remove,sort,unique,get
list,restore
See JSDoc in source for full details. Key methods:
envManager.getRaw(name, { scope })envManager.getExpanded(name, { scope })envManager.set(name, value, { scope, backup, verify, rollbackOnFail })envManager.unset(name, { scope, backup, verify, rollbackOnFail })envManager.path.{get,prepend,append,remove,sort,unique}({ ... })envManager.backup.{list,restore,setBackupDir,getBackupDir,purge}({ ... })
session: Only affects current processuser: User profile (Windows registry or ~/.profile)system: System-wide (Windows registry or /etc/environment)
- All changes to user/system env are backed up (unless
--backup false) - Rollback is attempted on failure if backup is enabled
- Backups are timestamped and auto-purged
The package entry points ("." and "./cli") resolve to the built dist/ files by default. In a checkout, the envm-dev export condition switches them to src/:
npm run build # esbuild, one file per src module → dist/ (index.mjs, index.cjs, cli.mjs, ...)
node --conditions=envm-dev app.mjs # run against src/
export NODE_OPTIONS=--conditions=envm-dev # or set it once per shellWithout the condition and without a build, importing the package fails with ERR_MODULE_NOT_FOUND for dist/. npm test runs the Vitest suite against src/ (the config passes the condition), then builds and checks the dist/ entries with node --test. npm run test:dist builds and runs the Vitest suite against dist/ instead of src/.
Apache-2.0 © Shinrai / CLDMV