CLI · @dotenv-run/cli
@dotenv-run/cli is a standalone CLI that can be used to run a script with environment variables defined in a .env file.
install
npm install -D @dotenv-run/cliusage
$> dotenv-run -h
Usage: dotenv-run [options] -- <command>
Options:
-h, --help output usage information -e, --env environment name (e.g. dev, prod) -s, --silent do not print .env file paths -r, --root root directory to search for .env files
Examples:
dotenv-run -- npm start dotenv-run -r ../.. -- npm start dotenv-run -e prod -- npm start.env file
Create a .env file with the following content:
API_HOST=api-sandbox.comAPI_INSTANCE=$USER-instanceAPI_BASE=https://$API_INSTANCE.$API_HOST/npx dotenv-run
Run dotenv-run using npx:
npx dotenv-run -- printenv✔ /home/chihab/sample/.env...API_HOST=api-sandbox.comAPI_INSTANCE=c.otmani-instanceAPI_BASE=https://c.otmani-instance.api-sandbox.com/command line
Override the value of API_INSTANCE from the command line:
API_INSTANCE=prod-instance npx dotenv-run -- printenv✔ /home/chihab/sample/.env...API_HOST=api-sandbox.comAPI_INSTANCE=prod-instanceAPI_BASE=https://prod-instance.api-sandbox.com/multiple .env files
Override the value of API_INSTANCE and API_HOST from the .env.prod file:
API_HOST=api.comAPI_INSTANCE=prod-instanceNODE_ENV=prod npx dotenv-run -- printenv✔ /home/chihab/sample/.env.prod✔ /home/chihab/sample/.env...API_HOST=api.comAPI_INSTANCE=prod-instanceAPI_BASE=https://prod-instance.api.com/process.env
Environment variables are available in process.env:
NODE_ENV=prod npx dotenv-run -- node -e "console.log(process.env.API_BASE)"✔ /home/chihab/sample/.env.prod✔ /home/chihab/sample/.envhttps://prod-instance.api.com/The list of options is the same as the ones supported by @dotenv-run/core. Please refer to the API section for more details.