env-cmd
A simple node program for executing commands using an environment from an env file.
💾 Install
npm install env-cmd or npm install -g env-cmd
⌨️ Basic Usage
Environment file ./.env
# This is a comment
ENV1=THANKS
ENV2=FOR ALL
ENV3=THE FISHPackage.json
{
"scripts": {
"test": "env-cmd -- mocha -R spec"
}
}Terminal
./node_modules/.bin/env-cmd -- node index.jsUsing custom env file path
To use a custom env filename or path, pass the -f flag. This is a major breaking change from prior versions < 9.0.0
Terminal
./node_modules/.bin/env-cmd -f ./custom/path/.env -- node index.js📜 Help
Usage: env-cmd [options] -- <command> [...args]
Options:
-v, --version output the version number
-e, --environments [envs...] The rc file environment(s) to use
-f, --file [path] Custom env file path or .rc file path if '-e' used (default path: ./.env or ./.env-cmdrc.(js|cjs|mjs|json))
-x, --expand-envs Replace $var and ${var} in args and command with environment variables
--recursive Replace $var and ${var} in env file with the referenced environment variable
--fallback Fallback to default env file path, if custom env file path not found
--no-override Do not override existing environment variables
--silent Ignore any env-cmd errors and only fail on executed program failure.
--use-shell Execute the command in a new shell with the given environment-h, --help display help for command