
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
@dotenv-run/cli
Advanced tools
A CLI tool to load command line and .env environment variables with monorepo support.
API_BASE=/v1/ dotenv-run -- npm start
.env
filesAPI_URL=$API_BASE/users
.env.production
).env.*
files (e.g. .env.production
> .env
)apps/next-app/.env
> apps/.env
> .env
dotenv-run -- python main.py
npm add -D @dotenv-run/cli
❯ npx dotenv-run
Usage: dotenv-run [options] -- <command>
Options:
-v, --verbose [regexp] display debug information
-u, --unsecure display environment variables values
-e, --env [environment] environment to load (default: NODE_ENV)
-r, --root root directory to search for .env files
-f, --file [.env,.secrets] .env files to load (default: .env)
-h, --help output usage information
Examples:
dotenv-run -d
dotenv-run -- npm start
dotenv-run -r ../.. -f .env,.secrets -- npm start
dotenv-run -f ../.env,../.env.api -- npm start
In addition to loading environment variables, @dotenv-run/cli supports monorepo projects with multiple applications.
In a monorepo configuration, .env.*
files can be defined in the root workspace and overriden by each application.
Root workspace
dotenv-run
will search and load .env.*
files located in the root workspace down to the current working directory.
If no root workspace is found, dotenv-run
will load environment files within the current working directory.
You can specify a root workspace with the -r
option.
Example
Given the following files:
platform
├── apps
│ ├── frontend1
│ │ ├── .env.local # API_USERS=http://localhost:3001/users
│ │ └── vite.config.js
│ └── frontend2
│ ├── package.json
│ └── webapp.config.mjs
├── .env.dev # API_BASE=https://dotenv-run.dev
├── .env.prod # API_BASE=https://dotenv-run.app
├── .env # API_USERS=$API_BASE/api/v1/users API_AUTH=https://$API_BASE/auth
├── nx.json
└── package.json
$> cd /platform
$> dotenv-run -e prod -- bash -c 'echo "✨ $API_USERS"'
✔ /platform/.env.prod
✔ /platform/.env
✨ https://dotenv-run.app/api/v1/users
$> cd /platform/apps/frontend1
$> dotenv-run -e dev -- bash -c 'printf "✨ API_USERS $API_USERS\n✨ API_AUTH $API_AUTH"'
✔ /platform/apps/frontend1/.env.local
✔ /platform/.env.dev
✔ /platform/.env
✨ API_USERS http://localhost:3001/users
✨ API_AUTH https://dotenv-run.dev/api/v1/auth
$> cd /platform/apps/frontend2
$> API_BASE=$CI_CONTAINER_API dotenv-run -- bash -c 'echo "✨ $API_USERS"'
✔ /platform/.env
✨ https://XAE221D1DE-ci-provider.cloud/api/v1/users
# CI_CONTAINER_API could be an environment variable provided by some CI provider
-r option
$> cd /platform/apps/frontend1
$> dotenv-run -r . -- bash -c 'echo "✨ $API_USERS"'
✔ /platform/apps/frontend1/.env.local
✨ http://localhost:3001/users
Paths to the root workspace can be relative or absolute, the following are all valid :
-r ../..
-r ../...env
-r /platform
-r /platform/.env
@dotenv-run/cli
uses dotenv to support loading environment variables from .env
files.
@dotenv-run/cli
loads .env
files with these specific names for the following -e ENV
value, files on the top have less priority than files on the bottom.
An env file for a specific mode (e.g. .env.production) will take higher priority than a generic one (e.g. .env).
valid .env filenames | ENV=* | ENV=test |
---|---|---|
.env | ✔️ | ✔️ |
.env.local | ✔️ | ✖️ |
.env.${ENV} | ✔️ | ✔️ |
.env.${ENV}.local | ✔️ | ✔️ |
In addition, environment variables that already exist when the CLI is executed have the highest priority and will not be overwritten by .env files. For example, when running SOME_KEY=123 dotenv-run
.
.env
You can expand variables already available on your machine for use in your .env
For example:
VERSION=$npm_package_version
HOSTNAME=$HOSTNAME
Or expand variables local to the current .env
file:
DOMAIN=www.example.com
FOO=$DOMAIN/foo
BAR=$DOMAIN/bar
Defining environment variables can vary between OSes. It’s also important to know that this manner is temporary for the life of the shell session.
set "API_URL=abcdef" && dotenv-run -- npm start
(Note: Quotes around the variable assignment are required to avoid a trailing whitespace.)
($env:API_URL = "abcdef") -and (dotenv-run -- npm start)
API_URL=abcdef dotenv-run -- npm start
In order to consume environment variables in your webapps, you need to expose them to the browser. The bundler you use will need to support replacing the environment variables at build time.
React, Vue.js...
Use Vite
Angular
Use @ngx-env/builder
MIT © Chihab Otmani
FAQs
cli to load environment variables with monorepo support
We found that @dotenv-run/cli demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.