{"name":"env-cmd","version":"11.0.0","description":"Executes a command using the environment variables in an env file","main":"dist/index.js","types":"dist/index.d.ts","type":"module","engines":{"node":">=20.10.0"},"bin":{"env-cmd":"bin/env-cmd.js"},"scripts":{"prepare":"husky","test":"mocha","test-cover":"c8 npm test","coveralls":"coveralls < coverage/lcov.info","lint":"npx eslint .","build":"tsc","watch":"tsc -w"},"repository":{"type":"git","url":"git+ssh://git@github.com/toddbluhm/env-cmd.git"},"keywords":["env","environment","cli","command","cmd","execute","run","file","variables","config"],"author":{"name":"Todd Bluhm"},"contributors":[{"name":"Anton Versal","email":"ant.ver@gmail.com"},{"name":"Eric Lanehart","email":"eric@pushred.co"},{"name":"Jon Scheiding","email":"jonscheiding@gmail.com"},{"name":"Kyle Hensel","email":"me@kyle.kiwi"},{"name":"Nicholas Krul","email":"nicholas.krul@gmail.com"},{"name":"serapath","email":"dev@serapath.de","url":"Alexander Praetorius"}],"license":"MIT","bugs":{"url":"https://github.com/toddbluhm/env-cmd/issues"},"homepage":"https://github.com/toddbluhm/env-cmd#readme","dependencies":{"@commander-js/extra-typings":"^13.1.0","commander":"^13.1.0","cross-spawn":"^7.0.6"},"devDependencies":{"@commitlint/cli":"^19.6.0","@commitlint/config-conventional":"^19.6.0","@eslint/js":"^9.16.0","@types/chai":"^5.0.1","@types/cross-spawn":"^6.0.6","@types/mocha":"^10.0.10","@types/node":"^24.0.10","@types/sinon":"^17.0.3","c8":"^10.1.2","chai":"^5.1.2","coveralls":"^3.0.0","esmock":"^2.6.9","globals":"^16.0.0","husky":"^9.1.7","mocha":"^11.0.0","sinon":"^21.0.0","tsx":"^4.19.2","typescript":"^5.7.2","typescript-eslint":"^8.15.0"},"commitlint":{"extends":["@commitlint/config-conventional"]},"c8":{"reporter":["text","lcov"]},"release":{"branches":["master"],"tagFormat":"${version}"},"publishConfig":{"provenance":true},"_id":"env-cmd@11.0.0","gitHead":"7242cb0e7f32cdd5c96ffc05126b0f440a4fa014","_nodeVersion":"24.6.0","_npmVersion":"11.5.1","dist":{"integrity":"sha512-gnG7H1PlwPqsGhFJNTv68lsDGyQdK+U9DwLVitcj1+wGq7LeOBgUzZd2puZ710bHcH9NfNeGWe2sbw7pdvAqDw==","shasum":"5912634c865f294a74745747d852aae07fd0d9a5","tarball":"http://registry-npm.ywwl.com/env-cmd/download/env-cmd-11.0.0.tgz","fileCount":33,"unpackedSize":55200,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/env-cmd@11.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIFeqeih/zUvTd9nv8wTN71bSG4uwrzK4TyGQ0XGB+KECAiBOYeJ1bkcXjWlAZWg0shgmPTfQw5QFPH/DMG4f+cj4gA=="}],"size":17233,"noattachment":false,"key":"/env-cmd/-/env-cmd-11.0.0.tgz"},"_npmUser":{"name":"toddbluhm","email":"toddbluhm@gmail.com"},"directories":{},"maintainers":[{"name":"toddbluhm","email":"toddbluhm@gmail.com"},{"name":"kyle.h","email":"thisiskyle@outlook.co.nz"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/env-cmd_11.0.0_1755919894429_0.782025727929367"},"_hasShrinkwrap":false,"readme":"[![Linux Tests](https://github.com/toddbluhm/env-cmd/workflows/linux%20tests/badge.svg)](https://github.com/toddbluhm/env-cmd/actions?query=workflow%3A%22linux%20tests%22)\n[![Windows Tests](https://github.com/toddbluhm/env-cmd/workflows/windows%20tests/badge.svg)](https://github.com/toddbluhm/env-cmd/actions?query=workflow%3A%22windows%20tests%22)\n[![Coverage Status](https://badgen.net/coveralls/c/github/toddbluhm/env-cmd)](https://coveralls.io/github/toddbluhm/env-cmd?branch=master)\n[![npm](https://badgen.net/npm/v/env-cmd)](https://www.npmjs.com/package/env-cmd)\n[![npm](https://badgen.net/npm/dm/env-cmd)](https://www.npmjs.com/package/env-cmd)\n[![License](https://badgen.net/github/license/toddbluhm/env-cmd)](https://github.com/toddbluhm/env-cmd/blob/master/LICENSE)\n[![Typescript-ESLint](https://badgen.net/badge/code%20style/typescript-eslint/blue?icon=typescript)](https://github.com/typescript-eslint/typescript-eslint)\n\n# env-cmd\n\nA simple node program for executing commands using an environment from an env file.\n\n## 💾 Install\n\n`npm install env-cmd` or `npm install -g env-cmd`\n\n## ⌨️ Basic Usage\n\n**Environment file `./.env`**\n\n```text\n# This is a comment\nENV1=THANKS\nENV2=FOR ALL\nENV3=THE FISH\n```\n\n**Package.json**\n\n```json\n{\n  \"scripts\": {\n    \"test\": \"env-cmd -- mocha -R spec\"\n  }\n}\n```\n\n**Terminal**\n\n```sh\n./node_modules/.bin/env-cmd -- node index.js\n```\n\n### Using custom env file path\n\nTo use a custom env filename or path, pass the `-f` flag. This is a major breaking change from prior versions < 9.0.0\n\n**Terminal**\n\n```sh\n./node_modules/.bin/env-cmd -f ./custom/path/.env -- node index.js\n```\n\n## 📜 Help\n\n```text\nUsage: env-cmd [options] -- <command> [...args]\n\nOptions:\n  -v, --version                 output the version number\n  -e, --environments [envs...]  The rc file environment(s) to use\n  -f, --file [path]             Custom env file path or .rc file path if '-e' used (default path: ./.env or ./.env-cmdrc.(js|cjs|mjs|json))\n  -x, --expand-envs             Replace $var and ${var} in args and command with environment variables\n  --recursive                   Replace $var and ${var} in env file with the referenced environment variable\n  --fallback                    Fallback to default env file path, if custom env file path not found\n  --no-override                 Do not override existing environment variables\n  --silent                      Ignore any env-cmd errors and only fail on executed program failure.\n  --use-shell                   Execute the command in a new shell with the given environment\n  --verbose                     Print helpful debugging information\n  -h, --help                    display help for command\n\n```\n\n## 🔬 Advanced Usage\n\n### `.rc` file usage\n\nFor more complex projects, a `.env-cmdrc` file can be defined in the root directory and supports\nas many environments as you want. Simply use the `-e` flag and provide which environments you wish to\nuse from the `.env-cmdrc` file. Using multiple environment names will merge the environment variables\ntogether. Later environments overwrite earlier ones in the list if conflicting environment variables\nare found.\n\n**.rc file `./.env-cmdrc`**\n\n```json\n{\n  \"development\": {\n    \"ENV1\": \"Thanks\",\n    \"ENV2\": \"For All\"\n  },\n  \"test\": {\n    \"ENV1\": \"No Thanks\",\n    \"ENV3\": \"!\"\n  },\n  \"production\": {\n    \"ENV1\": \"The Fish\"\n  }\n}\n```\n\n**Terminal**\n\n```sh\n./node_modules/.bin/env-cmd -e production -- node index.js\n# Or for multiple environments (where `production` vars override `test` vars,\n# but both are included)\n./node_modules/.bin/env-cmd -e test,production -- node index.js\n```\n\n### `--no-override` option\n\nPrevents overriding of existing environment variables on `process.env` and within the current\nenvironment.\n\n### `--fallback` file usage option\n\nIf the `.env` file does not exist at the provided custom path, then use the default\nfallback location `./.env` env file instead.\n\n### `--use-shell`\n\nExecutes the command within a new shell environment. This is useful if you want to string multiple\ncommands together that share the same environment variables.\n\n**Terminal**\n\n```sh\n./node_modules/.bin/env-cmd -f ./test/.env --use-shell -- \"npm run lint && npm test\"\n```\n\n### Asynchronous env file support\n\n   EnvCmd supports reading from asynchronous `.env` files. Instead of using a `.env` file, pass in a `.js`\n   file that exports either an object or a `Promise` resolving to an object (`{ ENV_VAR_NAME: value, ... }`). Asynchronous `.rc`\n   files are also supported using `.js` file extension and resolving to an object with top level environment\n   names (`{ production: { ENV_VAR_NAME: value, ... } }`).\n\n   **Terminal**\n\n   ```sh\n   ./node_modules/.bin/env-cmd -f ./async-file.js -- node index.js\n   ```\n\n### `-x` expands vars in arguments\n\nEnvCmd supports expanding `$var` values passed in as arguments to the command. The allows a user\nto provide arguments to a command that are based on environment variable values at runtime.\n\n**NOTE:** You must escape the `$` character with `\\` or your terminal might try to auto expand it before passing it to `env-cmd`.\n\n**Terminal**\n\n```sh\n# $VAR will be expanded into the env value it contains at runtime\n./node_modules/.bin/env-cmd -x -- node index.js --arg=\\$VAR\n```\n\nor in `package.json` (use `\\\\` to insert a literal backslash)\n```json\n{\n  \"script\": {\n    \"start\": \"env-cmd -x -- node index.js --arg=\\\\$VAR\"\n  }\n}\n```\n\n\n### `--silent` suppresses env-cmd errors\n\nEnvCmd supports the `--silent` flag the suppresses all errors generated by `env-cmd`\nwhile leaving errors generated by the child process and cli signals still usable. This\nflag is primarily used to allow `env-cmd` to run in environments where the `.env`\nfile might not be present, but still execute the child process without failing\ndue to a missing file.\n\n\n## 💿 Examples\n\nYou can find examples of how to use the various options above by visiting\nthe examples repo [env-cmd-examples](https://github.com/toddbluhm/env-cmd-examples).\n\n## 💽️ Environment File Formats\n\nThese are the currently accepted environment file formats. If any other formats are desired please create an issue.\n\n- `.env` as `key=value`\n- `.env.json` Key/value pairs as JSON\n- `.env.js` JavaScript file exporting an `object` or a `Promise` that resolves to an `object`\n- `.env-cmdrc` as valid json or `.env-cmdrc.json` in execution directory with at least one environment `{ \"dev\": { \"key1\": \"val1\" } }`\n- `.env-cmdrc.js` JavaScript file exporting an `object` or a `Promise` that resolves to an `object` that contains at least one environment\n\n## 🗂 Path Rules\n\nThis lib attempts to follow standard `bash` path rules. The rules are as followed:\n\nHome Directory = `/Users/test`\n\nWorking Directory = `/Users/test/Development/app`\n\n| Type | Input Path | Expanded Path |\n| -- | -- | ------------- |\n| Absolute | `/some/absolute/path.env` | `/some/absolute/path.env` |\n| Home Directory with `~` | `~/starts/on/homedir/path.env` | `/Users/test/starts/on/homedir/path.env` |\n| Relative | `./some/relative/path.env` or `some/relative/path.env` | `/Users/test/Development/app/some/relative/path.env` |\n| Relative with parent dir | `../some/relative/path.env` | `/Users/test/Development/some/relative/path.env` |\n\n## 🛠 API Usage\n\n### `EnvCmd`\n\nA function that executes a given command in a new child process with the given environment and options\n\n- **`options`** { `object` }\n  - **`command`** { `string` }: The command to execute (`node`, `mocha`, ...)\n  - **`commandArgs`** { `string[]` }: List of arguments to pass to the `command` (`['-R', 'Spec']`)\n  - **`envFile`** { `object` }\n    - **`filePath`** { `string` }: Custom path to .env file to read from (defaults to: `./.env`)\n    - **`fallback`** { `boolean` }: Should fall back to default `./.env` file if custom path does not exist\n  - **`rc`** { `object` }\n    - **`environments`** { `string[]` }: List of environment to read from the `.rc` file\n    - **`filePath`** { `string` }: Custom path to the `.rc` file (defaults to: `./.env-cmdrc(|.js|.json)`)\n  - **`options`** { `object` }\n    - **`expandEnvs`** { `boolean` }: Expand `$var` values passed to `commandArgs` (default: `false`)\n    - **`noOverride`** { `boolean` }: Prevent `.env` file vars from overriding existing `process.env` vars (default: `false`)\n    - **`silent`** { `boolean` }: Ignore any errors thrown by env-cmd, used to ignore missing file errors (default: `false`)\n    - **`useShell`** { `boolean` }: Runs command inside a new shell instance (default: `false`)\n    - **`verbose`** { `boolean` }: Prints extra debug logs to `console.info` (default: `false`)\n  - **Returns** { `Promise<object>` }: key is env var name and value is the env var value\n\n### `GetEnvVars`\n\nA function that parses environment variables from a `.env` or a `.rc` file\n\n- **`options`** { `object` }\n  - **`envFile`** { `object` }\n    - **`filePath`** { `string` }: Custom path to .env file to read from (defaults to: `./.env`)\n    - **`fallback`** { `boolean` }: Should fall back to default `./.env` file if custom path does not exist\n  - **`rc`** { `object` }\n    - **`environments`** { `string[]` }: List of environment to read from the `.rc` file\n    - **`filePath`** { `string` }: Custom path to the `.rc` file (defaults to: `./.env-cmdrc(|.js|.json)`)\n  - **`verbose`** { `boolean` }: Prints extra debug logs to `console.info` (default: `false`)\n- **Returns** { `Promise<object>` }: key is env var name and value is the env var value\n\n## 🧙 Why\n\nBecause sometimes it is just too cumbersome passing a lot of environment variables to scripts. It is\nusually just easier to have a file with all the vars in them, especially for development and testing.\n\n🚨**Do not commit sensitive environment data to a public git repo!** 🚨\n\n## 🧬 Related Projects\n\n[`cross-env`](https://github.com/kentcdodds/cross-env) - Cross platform setting of environment scripts\n\n## 📋 Contributing Guide\n\nI welcome all pull requests. Please make sure you add appropriate test cases for any features\nadded. Before opening a PR please make sure to run the following scripts:\n\n- `npm run lint` checks for code errors and format according to [ts-standard](https://github.com/toddbluhm/ts-standard)\n- `npm test` make sure all tests pass\n- `npm run test-cover` make sure the coverage has not decreased from current master\n","publish_time":1755919894652,"_cnpm_publish_time":1755919894652,"dist-tags":{"latest":"11.0.0"}}