@dotenvx/dotenvx
v2.38.0
Published
a secure dotenv–from the creator of `dotenv`
Readme
A secure dotenv–from the creator of dotenv.
- Encrypt
- Commit
- Ship
Quickstart

Install and use it in code just like dotenv.
npm install @dotenvx/dotenvx --save// index.js
require('@dotenvx/dotenvx').config()
// or import '@dotenvx/dotenvx/config' // for esm
console.log(`Hello ${process.env.HELLO}`)
or install globally - unlocks dotenv for any language, framework, or platform!
npm i -g @dotenvx/dotenvx
dotenvx encrypt
curl -sfS https://dotenvx.sh | sh
dotenvx encrypt
brew tap dotenvx/brew
brew trust dotenvx/brew
brew install dotenvx
dotenvx encrypt
docker run -it --rm -v $(pwd):/app dotenv/dotenvx encrypt
curl -L -o dotenvx.tar.gz "https://github.com/dotenvx/dotenvx/releases/latest/download/dotenvx-$(uname -s)-$(uname -m).tar.gz"
tar -xzf dotenvx.tar.gz
./dotenvx encrypt
winget install dotenvx
dotenvx encrypt
Usage
Encrypt your secrets in .env files. The values become ciphertext and only your private key can unlock them.
$ dotenvx encrypt
◈ encrypted (.env)To encrypt a fresh plaintext file with a public key created elsewhere:
dotenvx encrypt -f .env.production --with <public-key>This writes the supplied public key into the file and encrypts its values without creating or storing a private key. If every existing DOTENV_PUBLIC_KEY* entry matches the supplied key, it reuses that key, preserves existing ciphertext, and encrypts new plaintext values. A different public key, or an encrypted: value without a matching declared public key, fails with ALREADY_ENCRYPTED and leaves the file unchanged.
Commit your encrypted .env files with your code. It's safe. Now you can securely share secrets through git.
$ git add .env
$ git commit -m "encrypt .env"Ship your code and secrets together. Dotenvx uses your private key to decrypt and inject your secrets just-in-time to your code.
$ dotenvx run -- node index.js
⟐ injected env (2) from .env
Design
Three widely used and proven primitives make up Dotenvx's design. Git, .env, and secp256k1.
We chose git because it is the best way to deliver digital goods. It is the container ship of the digital world. All code travels on its ships. Why not secrets? Why invent an inferior secrets delivery mechanism when the world class one is right there at your fingertips.
We chose .env because it is the open standard for loading secrets into code. It represents environment variables, the core primitive that all secrets end up injected into at runtime of code.
Lastly, we needed to choose an encryption algorithm. Encryption of the values inside the .env file would allow us to place those values with code, leveraging git's distribution advantages while still following the twelve-factor config – by separating the decryption key from the code (environment).
It was important that we choose a proven, simple, asymmetric standard with small keys. We chose secp256k1, battle-tested by Bitcoin for more than seventeen years. We made cryptography an opinionated choice so developers wouldn't have to. Encryption just worked.
The result is a system built entirely from primitives, developers already understand, and infrastructure they already use. Secrets can travel with code without becoming part of the code. Git distributes them, .env defines how apps consume them, and secp256k1 keeps their values unreadable. The kicker, all this works by setting a single private key on your infrastructure - no more risky async coordination of secrets, no more centralized downtime risk. Your secrets are always just there with your code, ready to be unlocked at runtime.
Run Anywhere
$ echo "HELLO=World" > .env
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
$ node index.js
Hello undefined # without dotenvx
$ dotenvx run -- node index.js
Hello World # with dotenvx
> :-DMore examples
Run Claude with your real secrets while redacting them from its output.
Prerequisite: install Claude Code to get the claude command.
$ curl -fsSL https://claude.ai/install.sh | bash
$ claude --version$ echo "HELLO=World" > .env
$ dotenvx spec
$ dotenvx run -- claude -p 'Run `dotenvx get HELLO` and echo back just Hello VALUE' --dangerously-skip-permissions
Hello [REDACTED]Run Codex with your real secrets while redacting them from its output.
Prerequisite: install the Codex CLI to get the codex command.
$ npm install -g @openai/codex
$ codex --version$ echo "HELLO=World" > .env
$ dotenvx spec
$ dotenvx run -- codex exec 'Run `dotenvx get HELLO` and echo back just Hello VALUE' --skip-git-repo-check
Hello [REDACTED]Run Cursor with your real secrets while redacting them from its output.
Prerequisite: install the separate Cursor CLI. Installing the Cursor desktop app does not necessarily install the agent command.
$ curl https://cursor.com/install -fsS | bash
$ agent --version$ echo "HELLO=World" > .env
$ dotenvx spec
$ dotenvx run -- agent -p --force 'Run `dotenvx get HELLO` and echo back just Hello VALUE' --output-format text
Hello [REDACTED]Run with secrets resolved directly from 1Password.
$ echo "HELLO=op://Personal/hello/password" > .env
$ dotenvx run -- sh -c 'echo Hello $HELLO'
Hello Worldsee 1Password guide
Run with secrets resolved directly from Bitwarden Password Manager.
$ echo 'HELLO="bw://My Hello Login/password"' > .env
$ dotenvx run -- sh -c 'echo Hello $HELLO'
Hello WorldInstall the Bitwarden Password Manager CLI before running dotenvx.
// package.json
{
"type": "module",
"dependencies": {
"chalk": "^5.3.0"
}
}// index.ts
import chalk from 'chalk'
console.log(chalk.blue(`Hello ${process.env.HELLO}`))$ npm install
$ echo "HELLO=World" > .env
$ dotenvx run -- npx tsx index.ts
Hello WorldPreface Astro scripts with dotenvx run -- and read your env values in Astro.
{
"scripts": {
"dev": "dotenvx run -- astro dev",
"build": "dotenvx run -- astro build",
"preview": "dotenvx run -- astro preview"
}
}export async function GET() {
return new Response(
JSON.stringify({
HELLO: process.env.HELLO,
}),
{
status: 200,
headers: {
"Content-Type": "application/json",
},
}
);
}see astro guide
Preface Expo scripts with dotenvx run --.
{
"scripts": {
"start": "dotenvx run -- expo start",
"reset-project": "node ./scripts/reset-project.js",
"android": "dotenvx run -- expo start --android",
"ios": "dotenvx run -- expo start --ios",
"web": "dotenvx run -- expo start --web",
"lint": "expo lint"
}
}see expo guide
Install Dotenvx and @dotenvx/next-env.
$ npm install @dotenvx/dotenvx
$ npm install @dotenvx/next-envOverride @next/env in your package.json.
{
"overrides": {
"@next/env": "npm:@dotenvx/next-env"
}
}Encrypt your .env file.
$ npx dotenvx encrypt
◈ encrypted (.env)Your encrypted secrets are automatically injected and readable in Next.js.
import { NextResponse } from 'next/server'
export async function GET() {
return NextResponse.json({
HELLO: process.env.HELLO
})
}Set DOTENV_PRIVATE_KEY in production before deploying.
$ dotenvx encrypt -f .env.txt// src/index.js
import envSrc from '../.env.txt'
import dotenvx from '@dotenvx/dotenvx'
const config = dotenvx.config({ envs: [{ type: 'env', value: envSrc, privateKeyName: 'DOTENV_PRIVATE_KEY' }] })
const envx = config.parsed
export default {
async fetch(request, env, ctx) {
return new Response(`Hello ${envx.HELLO}`)
}
}"scripts": {
"deploy": "wrangler deploy",
"dev": "wrangler dev --var $(dotenvx keypair -f .env.txt --format=colon)",
"start": "wrangler dev --var $(dotenvx keypair -f .env.txt --format=colon)",
}$ echo "HELLO=Test" > .env.test
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
$ bun index.js
Hello undefined
$ dotenvx run -f .env.test -- bun index.js
Hello Test$ echo "HELLO=World" > .env
$ echo "console.log('Hello ' + Deno.env.get('HELLO'))" > index.ts
$ deno run --allow-env index.ts
Hello undefined
$ dotenvx run -- deno run --allow-env index.ts
Hello World[!WARNING] Some of you are attempting to use the npm module directly with
deno run. Don't, because deno currently has incomplete support for these encryption ciphers.$ deno run -A npm:@dotenvx/dotenvx encrypt Unknown cipherInstead, use
dotenvxas designed, by installing the cli as a binary - via curl, brew, etc.
$ echo "HELLO=World" > .env
$ echo 'import os;print("Hello " + os.getenv("HELLO", ""))' > index.py
$ dotenvx run -- python3 index.py
Hello World$ echo "HELLO=World" > .env
$ echo '<?php echo "Hello {$_SERVER["HELLO"]}\n";' > index.php
$ dotenvx run -- php index.php
Hello World$ echo "HELLO=World" > .env
$ echo 'puts "Hello #{ENV["HELLO"]}"' > index.rb
$ dotenvx run -- ruby index.rb
Hello World$ echo "HELLO=World" > .env
$ echo 'package main; import ("fmt"; "os"); func main() { fmt.Printf("Hello %s\n", os.Getenv("HELLO")) }' > main.go
$ dotenvx run -- go run main.go
Hello World$ echo "HELLO=World" > .env
$ echo 'fn main() {let hello = std::env::var("HELLO").unwrap_or("".to_string());println!("Hello {hello}");}' > src/main.rs
$ dotenvx run -- cargo run
Hello World$ echo "HELLO=World" > .env
$ echo 'public class Index { public static void main(String[] args) { System.out.println("Hello " + System.getenv("HELLO")); } }' > index.java
$ dotenvx run -- java index.java
Hello World$ echo "HELLO=World" > .env
$ echo '(println "Hello" (System/getenv "HELLO"))' > index.clj
$ dotenvx run -- clojure -M index.clj
Hello World$ echo "HELLO=World" > .env
$ echo 'fun main() { val hello = System.getenv("HELLO") ?: ""; println("Hello $hello") }' > index.kt
$ kotlinc index.kt -include-runtime -d index.jar
$ dotenvx run -- java -jar index.jar
Hello World$ dotnet new console -n HelloWorld -o HelloWorld
$ cd HelloWorld
$ echo "HELLO=World" | Out-File -FilePath .env -Encoding utf8
$ echo 'Console.WriteLine($"Hello {Environment.GetEnvironmentVariable("HELLO")}");' > Program.cs
$ dotenvx run -- dotnet run
Hello World$ echo "HELLO=World" > .env
$ dotenvx run --quiet -- sh -c 'echo Hello $HELLO'
Hello World$ dotenvx run -- next dev
$ dotenvx run -- npm start
$ dotenvx run -- bin/rails s
$ dotenvx run -- php artisan servesee framework guides
$ docker run -it --rm -v $(pwd):/app dotenv/dotenvx run -- node index.jsOr in any image:
FROM node:latest
RUN echo "HELLO=World" > .env && echo "console.log('Hello ' + process.env.HELLO)" > index.js
RUN curl -fsS https://dotenvx.sh/install.sh | sh
CMD ["/usr/local/bin/dotenvx", "run", "--", "echo", "Hello $HELLO"]see docker guide
name: build
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- run: curl -fsS https://dotenvx.sh/install.sh | sh
- run: dotenvx run -- node build.js
env:
DOTENV_KEY: ${{ secrets.DOTENV_KEY }}# heroku
heroku buildpacks:add https://github.com/dotenvx/heroku-buildpack-dotenvx
# docker
RUN curl -fsS https://dotenvx.sh | sh
# vercel
npm install @dotenvx/dotenvx --savesee platform guides
// pm2
"scripts": {
"start": "dotenvx run -- pm2-runtime start ecosystem.config.js --env production"
},# alternatively use npx
$ npx @dotenvx/dotenvx run -- node index.js
$ npx @dotenvx/dotenvx run -- next dev
$ npx @dotenvx/dotenvx run -- npm start$ npm install @dotenvx/dotenvx --save{
"scripts": {
"start": "./node_modules/.bin/dotenvx run -- node index.js"
},
"dependencies": {
"@dotenvx/dotenvx": "^0.5.0"
}
}$ npm run start
> start
> ./node_modules/.bin/dotenvx run -- node index.js
[[email protected]] injecting env (1) from .env.production
Hello WorldReference and expand variables already on your machine for use in your .env file.
# .env
USERNAME="username"
DATABASE_URL="postgres://${USERNAME}@localhost/my_database"// index.js
console.log('DATABASE_URL', process.env.DATABASE_URL)$ dotenvx run --debug -- node index.js
[[email protected]] injecting env (2) from .env
DATABASE_URL postgres://username@localhost/my_databaseAdd the output of a command to one of your variables in your .env file.
# .env
DATABASE_URL="postgres://$(whoami)@localhost/my_database"// index.js
console.log('DATABASE_URL', process.env.DATABASE_URL)$ dotenvx run --debug -- node index.js
[[email protected]] injecting env (1) from .env
DATABASE_URL postgres://yourusername@localhost/my_database
Multiple Environments
Create a
.env.productionfile and use-fto load it. It's straightforward, yet flexible.
$ echo "HELLO=production" > .env.production
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
$ dotenvx run -f .env.production -- node index.js
[[email protected]] injecting env (1) from .env.production
Hello production
> ^^More examples
$ echo "HELLO=local" > .env.local
$ echo "HELLO=World" > .env
$ dotenvx run -f .env.local,.env -- node index.js
[[email protected]] injecting env (1) from .env.local,.env
Hello localComma-separate multiple files after a single -f. Subsequent files do NOT override pre-existing variables defined in previous files or env. This follows historic principle. For example, above local wins – from the first file.
$ echo "HELLO=local" > .env.local
$ echo "HELLO=World" > .env
$ dotenvx run -f .env.local,.env --overload -- node index.js
[[email protected]] injecting env (1) from .env.local,.env
Hello WorldNote that with --overload subsequent files DO override pre-existing variables defined in previous files.
$ echo "HELLO=production" > .env.production
$ dotenvx run -f .env.production --verbose -- node index.js
[dotenvx][verbose] injecting env from /path/to/.env.production
[dotenvx][verbose] HELLO set
[[email protected]] injecting env (1) from .env.production
Hello production$ echo "HELLO=production" > .env.production
$ dotenvx run -f .env.production --debug -- node index.js
[dotenvx][debug] configuring options
[dotenvx][debug] {"envFile":[".env.production"]}
[dotenvx][verbose] injecting env from /path/to/.env.production
[dotenvx][debug] reading env from /path/to/.env.production
[dotenvx][debug] parsing env from /path/to/.env.production
[dotenvx][debug] {"HELLO":"production"}
[dotenvx][debug] writing env from /path/to/.env.production
[dotenvx][verbose] HELLO set
[dotenvx][debug] HELLO set to production
[[email protected]] injecting env (1) from .env.production
Hello productionUse --quiet to suppress all output (except errors).
$ echo "HELLO=production" > .env.production
$ dotenvx run -f .env.production --quiet -- node index.js
Hello productionYou can also set DOTENV_QUIET=true.
$ DOTENV_QUIET=true dotenvx run -f .env.production -- node index.js
Hello productionSet --log-level to whatever you wish. For example, to suppress warnings (risky), set log level to error:
$ echo "HELLO=production" > .env.production
$ dotenvx run -f .env.production --log-level=error -- node index.js
Hello productionAvailable log levels are error, warn, info, verbose, debug, silly
Load envs using Next.js' convention or dotenv-flow convention. Set --convention to nextjs or flow:
$ echo "HELLO=development local" > .env.development.local
$ echo "HELLO=local" > .env.local
$ echo "HELLO=development" > .env.development
$ echo "HELLO=env" > .env
$ dotenvx run --convention=nextjs -- node index.js
Hello development local
$ dotenvx run --convention=flow -- node index.js
Hello development local(more conventions available upon request)
Encryption
Add encryption to your
.envfiles with a single command. Usedotenvx encrypt.
$ dotenvx encrypt
◈ encrypted (.env)A
DOTENV_PUBLIC_KEY(encryption key) and aDOTENV_PRIVATE_KEY(decryption key) are generated using the same public-key cryptography as Bitcoin.
More examples
$ echo "HELLO=World" > .env
$ dotenvx encrypt
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
$ dotenvx run -- node index.js
[[email protected]] injecting env (2) from .env
Hello World$ echo "HELLO=Production" > .env.production
$ dotenvx encrypt -f .env.production
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
$ DOTENV_PRIVATE_KEY_PRODUCTION="<.env.production private key>" dotenvx run -- node index.js
[[email protected]] injecting env (2) from .env.production
Hello ProductionNote the DOTENV_PRIVATE_KEY_PRODUCTION ends with _PRODUCTION. This instructs dotenvx run to load the .env.production file.
$ echo "HELLO=Ci" > .env.ci
$ dotenvx encrypt -f .env.ci
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
$ DOTENV_PRIVATE_KEY_CI="<.env.ci private key>" dotenvx run -- node index.js
[[email protected]] injecting env (2) from .env.ci
Hello CiNote the DOTENV_PRIVATE_KEY_CI ends with _CI. This instructs dotenvx run to load the .env.ci file. See the pattern?
$ dotenvx set HELLO World -f .env
$ dotenvx set HELLO Production -f .env.production
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
$ DOTENV_PRIVATE_KEY="<.env private key>" DOTENV_PRIVATE_KEY_PRODUCTION="<.env.production private key>" dotenvx run -- node index.js
[[email protected]] injecting env (3) from .env, .env.production
Hello WorldNote the DOTENV_PRIVATE_KEY instructs dotenvx run to load the .env file and the DOTENV_PRIVATE_KEY_PRODUCTION instructs it to load the .env.production file. See the pattern?
Point -f at a directory to load the .env inside it. From a workspace, this makes a shared root .env available without repeating its filename.
my-monorepo/
.env
apps/
web/
index.js$ dotenvx encrypt
$ cd apps/web
$ dotenvx get HELLO -f ../..
World
$ dotenvx run -f ../.. -- node index.js
[[email protected]] injecting env (1) from ../../.env
Hello WorldWith the private key in your OS secret store, dotenvx finds it automatically from any workspace on the same machine.
The directory also becomes the base when using a convention:
$ dotenvx run -f ../.. --convention=nextjs -- node index.js
[[email protected]] injecting env (1) from ../../.env.development.local, ../../.env.local, ../../.env.development, ../../.env
Hello development localFor a workspace with its own encrypted .env, run from that workspace:
$ dotenvx run -- node index.js$ echo "HELLO=World" > .env
$ dotenvx encrypt --stdout
$ dotenvx encrypt --stdout > .env.encrypted
secp256k1is a well-known and battle tested curve, in use with Bitcoin and other cryptocurrencies, but we are open to adding support for more curves.If your organization's compliance department requires NIST approved curves or other curves like
curve25519, please reach out at [email protected].
Advanced
Become a
dotenvxpower user.
CLI 📟
Advanced CLI commands.
Reference and expand variables already on your machine for use in your .env file.
# .env
USERNAME="username"
DATABASE_URL="postgres://${USERNAME}@localhost/my_database"// index.js
console.log('DATABASE_URL', process.env.DATABASE_URL)$ dotenvx run --debug -- node index.js
[[email protected]] injecting env (2) from .env
DATABASE_URL postgres://username@localhost/my_databaseUse default values when environment variables are unset or empty.
# .env
# Default value syntax: use value if set, otherwise use default
DATABASE_HOST=${DB_HOST:-localhost}
DATABASE_PORT=${DB_PORT:-5432}
# Alternative syntax (no colon): use value if set, otherwise use default
API_URL=${API_BASE_URL-https://api.example.com}// index.js
console.log('DATABASE_HOST', process.env.DATABASE_HOST)
console.log('DATABASE_PORT', process.env.DATABASE_PORT)
console.log('API_URL', process.env.API_URL)$ dotenvx run --debug -- node index.js
[[email protected]] injecting env (3) from .env
DATABASE_HOST localhost
DATABASE_PORT 5432
API_URL https://api.example.comUse alternate values when environment variables are set and non-empty.
# .env
NODE_ENV=production
# Alternate value syntax: use alternate if set and non-empty, otherwise empty
DEBUG_MODE=${NODE_ENV:+false}
LOG_LEVEL=${NODE_ENV:+error}
# Alternative syntax (no colon): use alternate if set, otherwise empty
CACHE_ENABLED=${NODE_ENV+true}// index.js
console.log('NODE_ENV', process.env.NODE_ENV)
console.log('DEBUG_MODE', process.env.DEBUG_MODE)
console.log('LOG_LEVEL', process.env.LOG_LEVEL)
console.log('CACHE_ENABLED', process.env.CACHE_ENABLED)$ dotenvx run --debug -- node index.js
[[email protected]] injecting env (4) from .env
NODE_ENV production
DEBUG_MODE false
LOG_LEVEL error
CACHE_ENABLED trueComplete reference for variable interpolation patterns supported by dotenvx:
# .env
DEFINED_VAR=hello
EMPTY_VAR=
# UNDEFINED_VAR is not set
# Default value syntax - use variable if set/non-empty, otherwise use default
TEST1=${DEFINED_VAR:-fallback} # Result: "hello"
TEST2=${EMPTY_VAR:-fallback} # Result: "fallback"
TEST3=${UNDEFINED_VAR:-fallback} # Result: "fallback"
# Default value syntax (no colon) - use variable if set, otherwise use default
TEST4=${DEFINED_VAR-fallback} # Result: "hello"
TEST5=${EMPTY_VAR-fallback} # Result: "" (empty, but set)
TEST6=${UNDEFINED_VAR-fallback} # Result: "fallback"
# Alternate value syntax - use alternate if variable is set/non-empty, otherwise empty
TEST7=${DEFINED_VAR:+alternate} # Result: "alternate"
TEST8=${EMPTY_VAR:+alternate} # Result: "" (empty)
TEST9=${UNDEFINED_VAR:+alternate} # Result: "" (empty)
# Alternate value syntax (no colon) - use alternate if variable is set, otherwise empty
TEST10=${DEFINED_VAR+alternate} # Result: "alternate"
TEST11=${EMPTY_VAR+alternate} # Result: "alternate" (empty but set)
TEST12=${UNDEFINED_VAR+alternate} # Result: "" (empty)Key differences:
:-vs-: The colon makes empty values trigger the fallback:+vs+: The colon makes empty values not trigger the alternate- Default syntax (
-): Use variable value or fallback - Alternate syntax (
+): Use alternate value or empty string
Add the output of a command to one of your variables in your .env file.
# .env
DATABASE_URL="postgres://$(whoami)@localhost/my_database"// index.js
console.log('DATABASE_URL', process.env.DATABASE_URL)$ dotenvx run --debug -- node index.js
[[email protected]] injecting env (1) from .env
DATABASE_URL postgres://yourusername@localhost/my_databasePrevent your shell from expanding inline $VARIABLES before dotenvx has a chance to inject it. Use a subshell.
$ dotenvx run --env="HELLO=World" -- sh -c 'echo Hello $HELLO'
Hello WorldDotenvx supports multiline values. This is particularly useful in conjunction with Docker - which does not support multiline values.
# .env
MULTILINE_PEM="-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnNl1tL3QjKp3DZWM0T3u
LgGJQwu9WqyzHKZ6WIA5T+7zPjO1L8l3S8k8YzBrfH4mqWOD1GBI8Yjq2L1ac3Y/
bTdfHN8CmQr2iDJC0C6zY8YV93oZB3x0zC/LPbRYpF8f6OqX1lZj5vo2zJZy4fI/
kKcI5jHYc8VJq+KCuRZrvn+3V+KuL9tF9v8ZgjF2PZbU+LsCy5Yqg1M8f5Jp5f6V
u4QuUoobAgMBAAE=
-----END PUBLIC KEY-----"// index.js
console.log('MULTILINE_PEM', process.env.MULTILINE_PEM)$ dotenvx run -- node index.js
MULTILINE_PEM -----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnNl1tL3QjKp3DZWM0T3u
LgGJQwu9WqyzHKZ6WIA5T+7zPjO1L8l3S8k8YzBrfH4mqWOD1GBI8Yjq2L1ac3Y/
bTdfHN8CmQr2iDJC0C6zY8YV93oZB3x0zC/LPbRYpF8f6OqX1lZj5vo2zJZy4fI/
kKcI5jHYc8VJq+KCuRZrvn+3V+KuL9tF9v8ZgjF2PZbU+LsCy5Yqg1M8f5Jp5f6V
u4QuUoobAgMBAAE=
-----END PUBLIC KEY-----Unlike other dotenv libraries, dotenvx attempts to unblock you with contextual help.
For example, when missing a custom .env file:
$ dotenvx run -f .env.missing -- echo $HELLO
[MISSING_ENV_FILE] missing file (/Users/scottmotte/Code/dotenvx/playground/apr-16/.env.missing). fix: [echo "HELLO=World" > .env.missing]or when missing a KEY:
$ echo "HELLO=World" > .env
$ dotenvx get GOODBYE
[MISSING_KEY] missing key (GOODBYE)Resolve 1Password op:// directly from your .env file.
# .env
API_KEY=op://Personal/my_api_key/passwordInstall the 1Password CLI and authenticate with op. Dotenvx automatically reads op:// values through op read before injecting them.
$ dotenvx run -- node index.jsUse --no-1password to leave op:// values unresolved.
$ dotenvx run --no-1password -- node index.jsThe same flag is available for dotenvx get and dotenvx check.
Resolve bw:// references directly from your .env file through the Bitwarden Password Manager CLI.
# .env
API_KEY="bw://My GitHub Account/password"The reference format is bw://<item>/<field>. The item can be a human-readable Bitwarden search term or an exact item UUID. Quote the dotenv value when the item name contains spaces.
Supported fields are:
usernamepassworduri
When the vault is locked in an interactive terminal, dotenvx prompts for your Bitwarden master password.
Human-readable names are convenient, but must identify a single item. If multiple items match, Bitwarden returns an error. Use the item UUID when you need an unambiguous reference.
If Bitwarden cannot resolve a reference, dotenvx reports the error and leaves the original bw:// value unresolved.
Use --no-bitwarden to skip Bitwarden resolution intentionally.
$ dotenvx run --no-bitwarden -- node index.jsThe same flag is available for dotenvx get and dotenvx check.
Run a command using the .env file in a directory. This is useful with monorepos.
$ dotenvx run -f ../.. -- node index.js
[[email protected]] injecting env (1) from ../../.env
Hello WorldCompose multiple .env files for environment variables loading, as you need.
$ echo "HELLO=local" > .env.local
$ echo "HELLO=World" > .env
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
$ dotenvx run -f .env.local,.env -- node index.js
[[email protected]] injecting env (1) from .env.local, .env
Hello localComma-separate multiple files after a single -f. Subsequent files do NOT override pre-existing variables defined in previous files or env. This follows historic principle. For example, above local wins – from the first file.
Set environment variables as a simple KEY=value string pair.
$ echo "HELLO=World" > .env
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
$ dotenvx run --env HELLO=String -f .env -- node index.js
[[email protected]] injecting env (1) from .env, and --env flag
Hello StringRun any command with real environment variables while automatically redacting values selected by your Envfile from stdout and stderr.
$ echo "SECRET=super-secret-value" > .env
$ echo "PUBLIC_VALUE=visible-value" >> .env
$ echo "console.log(process.env.SECRET, process.env.PUBLIC_VALUE)" > index.js
$ dotenvx spec
$ dotenvx run --quiet -- node index.js
[REDACTED] visible-valueWith an Envfile, all values are redacted by default. Use redacted: false on individual declarations to leave those values visible. spec generates these settings, including public-name exceptions. If an existing environment variable takes precedence, its effective value follows the same rules. Matching is exact, so transformed or derived values are not redacted.
Without an Envfile, dotenvx run --redact -- yourcommand redacts loaded values except recognized public names (containing PUBLIC or starting with VITE, case-sensitive). _PLAIN values are redacted too. Without either an Envfile or --redact, output is not redacted. An Envfile always takes precedence: its rules apply automatically, even when --redact is passed.
When stdin, stdout, and stderr are attached to a terminal, dotenvx preserves interactive behavior on macOS and Linux systems with script available. Piped and redirected commands continue to use normal stdin, stdout, and stderr streams.
Run Claude in print mode with real environment variables while redacting any values it prints.
$ echo "SECRET=super-secret-value" > .env
$ dotenvx spec
$ dotenvx run --quiet -- claude -p 'Print the value of $SECRET'
[REDACTED]Start a fully interactive Claude session. Claude receives the real values, but any values it prints are redacted.
$ echo "SECRET=super-secret-value" > .env
$ dotenvx spec
$ dotenvx run --quiet -- claudeRun Codex non-interactively with real environment variables while redacting any values it prints.
$ echo "SECRET=super-secret-value" > .env
$ dotenvx spec
$ dotenvx run --quiet -- codex exec 'Print the value of $SECRET'
[REDACTED]Start a fully interactive Codex session. Codex receives the real values, but any values it prints are redacted.
$ echo "SECRET=super-secret-value" > .env
$ dotenvx spec
$ dotenvx run --quiet -- codexOverride existing env variables. These can be variables already on your machine or variables loaded as files consecutively. The last variable seen will 'win'.
$ echo "HELLO=local" > .env.local
$ echo "HELLO=World" > .env
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
$ dotenvx run -f .env.local,.env --overload -- node index.js
[[email protected]] injecting env (1) from .env.local, .env
Hello WorldNote that with --overload subsequent files DO override pre-existing variables defined in previous files.
When deploying applications in containers or cloud environments, you often need to override specific environment variables at runtime without modifying committed .env files. By default, dotenvx follows the historic dotenv principle: environment variables already present take precedence over .env files.
# .env.prod contains: MODEL_REGISTRY=registry.company.com/models/v1
$ echo "MODEL_REGISTRY=registry.company.com/models/v1" > .env.prod
$ echo "console.log('MODEL_REGISTRY:', process.env.MODEL_REGISTRY)" > app.js
# Without environment variable set - uses .env.prod value
$ dotenvx run -f .env.prod -- node app.js
MODEL_REGISTRY: registry.company.com/models/v1
# With environment variable set (e.g., via Azure Container Service) - environment variable takes precedence
$ MODEL_REGISTRY=registry.azure.com/models/v2 dotenvx run -f .env.prod -- node app.js
MODEL_REGISTRY: registry.azure.com/models/v2
# To force .env.prod to override environment variables, use --overload
$ MODEL_REGISTRY=registry.azure.com/models/v2 dotenvx run -f .env.prod --overload -- node app.js
MODEL_REGISTRY: registry.company.com/models/v1For container deployments: Set environment variables through your cloud provider's UI/configuration (Azure Container Service, AWS ECS, etc.) to override specific values from committed .env files without rebuilding your application.
Decrypt your encrypted .env by setting DOTENV_PRIVATE_KEY before dotenvx run.
$ touch .env
$ dotenvx set HELLO encrypted
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
# check your .env.keys files for your privateKey
$ DOTENV_PRIVATE_KEY="122...0b8" dotenvx run -- node index.js
[[email protected]] injecting env (2) from .env
Hello encryptedDecrypt your encrypted .env.production by setting DOTENV_PRIVATE_KEY_PRODUCTION before dotenvx run. Alternatively, this can be already set on your server or cloud provider.
$ touch .env.production
$ dotenvx set HELLO "production encrypted" -f .env.production
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
# check .env.keys for your privateKey
$ DOTENV_PRIVATE_KEY_PRODUCTION="122...0b8" dotenvx run -- node index.js
[[email protected]] injecting env (2) from .env.production
Hello production encryptedNote the DOTENV_PRIVATE_KEY_PRODUCTION ends with _PRODUCTION. This instructs dotenvx run to load the .env.production file.
Decrypt your encrypted .env.ci by setting DOTENV_PRIVATE_KEY_CI before dotenvx run. Alternatively, this can be already set on your server or cloud provider.
$ touch .env.ci
$ dotenvx set HELLO "ci encrypted" -f .env.ci
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
# check .env.keys for your privateKey
$ DOTENV_PRIVATE_KEY_CI="122...0b8" dotenvx run -- node index.js
[[email protected]] injecting env (2) from .env.ci
Hello ci encryptedNote the DOTENV_PRIVATE_KEY_CI ends with _CI. This instructs dotenvx run to load the .env.ci file. See the pattern?
Decrypt your encrypted .env and .env.production files by setting DOTENV_PRIVATE_KEY and DOTENV_PRIVATE_KEY_PRODUCTION before dotenvx run.
$ touch .env
$ touch .env.production
$ dotenvx set HELLO encrypted
$ dotenvx set HELLO "production encrypted" -f .env.production
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
# check .env.keys for your privateKeys
$ DOTENV_PRIVATE_KEY="122...0b8" DOTENV_PRIVATE_KEY_PRODUCTION="122...0b8" dotenvx run -- node index.js
[[email protected]] injecting env (3) from .env, .env.production
Hello encrypted
$ DOTENV_PRIVATE_KEY_PRODUCTION="122...0b8" DOTENV_PRIVATE_KEY="122...0b8" dotenvx run -- node index.js
[[email protected]] injecting env (3) from .env.production, .env
Hello production encryptedCompose any encrypted files you want this way. As long as a DOTENV_PRIVATE_KEY_${environment} is set, the values from .env.${environment} will be decrypted at runtime.
Set log level to verbose. (log levels)
$ echo "HELLO=production" > .env.production
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
$ dotenvx run -f .env.production --verbose -- node index.js
loading env from .env.production (/path/to/.env.production)
HELLO set
[[email protected]] injecting env (1) from .env.production
Hello productionSet log level to debug. (log levels)
$ echo "HELLO=production" > .env.production
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
$ dotenvx run -f .env.production --debug -- node index.js
process command [node index.js]
options: {"env":[],"envFile":[".env.production"]}
loading env from .env.production (/path/to/.env.production)
{"HELLO":"production"}
HELLO set
HELLO set to production
[[email protected]] injecting env (1) from .env.production
executing process command [node index.js]
expanding process command to [/opt/homebrew/bin/node index.js]
Hello productionUse --quiet to suppress all output (except errors). (log levels)
$ echo "HELLO=production" > .env.production
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
$ dotenvx run -f .env.production --quiet -- node index.js
Hello productionYou can also set DOTENV_QUIET=true.
$ DOTENV_QUIET=true dotenvx run -f .env.production -- node index.js
Hello productionSet --log-level to whatever you wish. For example, to suppress warnings (risky), set log level to error:
$ echo "HELLO=production" > .env.production
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
$ dotenvx run -f .env.production --log-level=error -- node index.js
Hello productionAvailable log levels are error, warn, info, verbose, debug, silly (source)
Envfile is like a Dockerfile for your secrets.
When an Envfile is present, run and check validate the same requirements: required values, types, enums, and ranges. No validation flag is needed. run performs validation before starting your command.
# Envfile
env "DATABASE_URL", type: "url"
env "API_KEY"
env "SENTRY_DSN", optional: true$ dotenvx run -- node index.js
[INVALID_ENV] DATABASE_URL is required; API_KEY is requiredEnvfile validation failures warn by default; run --strict stops before launching the command. A strict true setting in Envfile, at the root or in an active file block, also makes its validation failures fatal. check always exits with failure when validation fails. Strictness changes enforcement, not which rules are checked. Invalid Envfile syntax always stops execution.
Envfile values default to redacted: true: run masks their values in child stdout/stderr and resolved-value debug output, while the child still receives the real values. Set redacted: false for values that may appear in output. This is independent of encrypted: true, which controls encryption in encrypt, set, and protect.
The synchronous dotenvx.config() API also reads Envfile from the current working directory and validates the final resolved values using the same rules, including selected file blocks. Validation failures warn and are returned in { parsed, error }; config({ strict: true }) or an applicable Envfile strict true setting makes failures throw. ignore: ['INVALID_ENV'] suppresses validation failures. Invalid Envfile syntax always throws before loading values. With an Envfile, config() automatically redacts subsequent writes through Node's stdout/stderr streams, including existing console.log and console.error calls. Environment values and returned values stay unchanged. Repeated calls retain earlier secrets and add newly loaded ones. An unfinished secret prefix is masked at shutdown. Direct native writes and child processes inheriting file descriptors bypass these wrappers; use dotenvx run to capture child output.
file ".env.development" do
env "BASE_URL", type: "url", redacted: false
env "TOKEN_SECRET", encrypted: true
endspec generates declarations with encryption and redaction required by default. Encryption is required by default: root and file-level encrypted settings are not supported. Use encrypted: false on individual declarations to permit plaintext. Entirely plaintext inputs generate no encryption exceptions except for keys ending in _PLAIN, so the next encrypt encrypts the remaining values. _PLAIN keys get encrypted: false only when none of their assignments contain ciphertext; code-only references do not infer this exception. For files that already contain ciphertext, spec preserves plaintext values with per-key exceptions. Source files are never modified.
spec infers redacted: false for names starting with PUBLIC, VITE, NEXT_PUBLIC, or NUXT_PUBLIC, or containing PUBLIC anywhere (case-sensitive). This affects visibility only; public names still require encryption unless explicitly exempted. Other names, including those ending in _PLAIN, remain redacted.
dotenvx spec always generates Envfile with strict true at the top, including with --overwrite or --stdout. Generated policies stop commands on validation failures. Existing policies that omit strict continue to warn.
If an Envfile already exists, spec leaves it untouched and prints ○ Envfile already exists [edit or run: spec --overwrite]. Use spec --overwrite to regenerate it from the selected inputs, replacing custom rules, comments, and blocks for files absent from this machine. Interactive overwrite runs show the full file-and-code checklist with the prompt Recreate Envfile from .env files and code. Noninteractive runs use .env.example and .env, or the file selected with -f. Input validation finishes before the old Envfile is replaced; cancelled selection leaves it untouched. Symlinked Envfiles cannot be overwritten.
Use dotenvx spec --stdout to print the generated Envfile without writing it, or dotenvx spec --stdout -f .env.production to select an input file. This works even when an Envfile already exists; --stdout leaves it untouched even with --overwrite. Prompts and progress stay on stderr so stdout contains only the generated content.
Root and file-level redacted settings are not supported. Use per-key redacted: false to permit output visibility. When selected files specify conflicting options, the first file's explicit option wins. check previews values with policy-driven redaction and reports issues per key.
Use exact file blocks to override rules for selected files:
env "HELLO"
env "PORT", type: "port"
env "STRIPE_SECRET_KEY", optional: true
file ".env.production" do
env "STRIPE_SECRET_KEY", required: true
env "PORT", min: 1024
endProfiles select file combinations:
profile "development", files: [".env.local", ".env"]
profile "production", files: [".env.production"]Selection order is explicit -f, --profile, DOTENV_FILE / DOTENV_PATH / DOTENV_F, then DOTENV_ENV, APP_ENV, RAILS_ENV, RACK_ENV, MIX_ENV, and NODE_ENV. Without a selector, the development profile is used if declared; otherwise .env. Explicit unknown profiles fail.
Both dotenvx run -f .env.production -- node index.js and dotenvx check -f .env.production use the production rules. Block declarations inherit top-level options and override only the options they specify. Encryption and redaction are specified per key.
Paths in file blocks are relative to the Envfile. They match the selected paths exactly after path normalization (./.env.production matches .env.production); they are not basename matches or globs. Directory inputs and DOTENV_FILE use their resolved file paths.
When no file block matches, top-level rules apply. Selected file blocks override explicit options in file order: the first file wins. Policy selection is independent of where the final value comes from, including shell values and --overload. A selected missing file still activates its block. Blocks cannot be nested, and duplicate declarations within one scope or duplicate file blocks are errors.
Validate the final resolved environment against your Envfile, using the same loader and precedence as run:
$ dotenvx check -f .env.local -f .env
✔ PORT=3000 # .env.local:1
$ dotenvx check -f .env.production
☠ PORT=bad # .env.production:4 !portEnvfile file blocks define policy; they do not select files to load. By default, check uses the same profile and file selection as run. Use repeated -f flags or --convention to select layers. DOTENV_FILE and its aliases are also supported.
All selected sources are merged before validation. The first file wins by default, existing shell values take precedence, and --overload lets later sources override earlier values. Partial files can satisfy the schema together. Validation checks final values; encryption requirements are enforced separately by encrypt, set, and protect. Rules are combined independently, with the first explicit file option winning.
Missing files explicitly selected with -f or DOTENV_FILE (and its aliases) fail the check. Missing optional convention layers and implicit default files are reported as ○ skipped (filename). check has no --strict flag. Required values must still resolve; shell or inline values can satisfy the schema without a local file. A check with no readable files, inline values, or declared shell values fails rather than reporting an empty success.
The preview shows redacted values and per-key diagnostics on stdout, with source locations where available. Loading errors go to stderr. --quiet suppresses the preview. Failed checks exit with code 1.
The Git protection filter reads Envfile in the same directory as the file being staged. Encryption is required by default. Keys explicitly marked encrypted: false may be committed as plaintext:
env "BASE_URL", encrypted: false
env "TOKEN_SECRET"This permits plaintext BASE_URL while requiring TOKEN_SECRET and undeclared keys to be encrypted. Only keys explicitly marked encrypted: false may remain plaintext. redacted only controls output visibility.
Without an Envfile, protection keeps its existing rules, including exemptions for .env.example, .env.vault, and .env.x. A _PLAIN suffix alone does not permit plaintext through Git protection.
Protection inspects every assignment in the incoming Git blob, including duplicates. It does not merge files, use shell overrides, or decrypt values. Empty values, public encryption keys, and op:// / bw:// references remain allowed. Private-key files (.env.keys*) and nonempty plaintext DOTENV_PRIVATE_KEY values remain blocked even with encrypted: false.
The policy is read from the working-tree Envfile beside the staged file, even if that policy itself is unstaged. If no adjacent Envfile exists, the Git repository root is checked. Invalid or unreadable policies block staging with an error. Envfile encryption rules also apply to otherwise exempt files such as .env.example.
Accepted blobs pass through byte-for-byte. This integration applies to Git protection, not protect --docker.
Exit with code 1 if any errors are encountered - like a missing .env file or decryption failure.
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
$ dotenvx run -f .env.missing --strict -- node index.js
[MISSING_ENV_FILE] missing file (/path/to/.env.missing). fix: [echo "HELLO=World" > .env.missing]This can be useful in ci scripts where you want to fail the ci if your .env file could not be decrypted at runtime.
Ignore errors like MISSING_ENV_FILE.
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
$ dotenvx run -f .env.missing --ignore=MISSING_ENV_FILE -- node index.js
...You can also set DOTENV_IGNORE="MISSING_ENV_FILE". It is parsed as a comma-separated list.
$ DOTENV_IGNORE="MISSING_ENV_FILE,OTHER_ERROR_CODE" dotenvx run -f .env.missing -- node index.jsLoad envs using Next.js' convention. Set --convention to nextjs:
$ echo "HELLO=development local" > .env.development.local
$ echo "HELLO=local" > .env.local
$ echo "HELLO=development" > .env.development
$ echo "HELLO=env" > .env
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
$ dotenvx run --convention=nextjs -- node index.js
[[email protected]] injecting env (1) from .env.development.local, .env.local, .env.development, .env
Hello development localYou can also set DOTENV_CONVENTION=nextjs.
$ DOTENV_CONVENTION=nextjs dotenvx run -- node index.js
[[email protected]] injecting env (1) from .env.development.local, .env.local, .env.development, .env
Hello development local(more conventions available upon request)
Run a command using Next.js' convention from a directory. This is useful with monorepos.
$ dotenvx run -f ../.. --convention=nextjs -- node index.js
[[email protected]] injecting env (1) from ../../.env.development.local, ../../.env.local, ../../.env.development, ../../.env
Hello development localLoad envs using dotenv-flow's convention. Set --convention to flow:
$ echo "HELLO=development local" > .env.development.local
$ echo "HELLO=development" > .env.development
$ echo "HELLO=local" > .env.local
$ echo "HELLO=env" > .env
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
$ NODE_ENV=development dotenvx run --convention=flow -- node index.js
[[email protected]] injecting env (1) from .env.development.local, .env.development, .env.local, .env
Hello development localYou can also set DOTENV_CONVENTION=flow.
$ NODE_ENV=development DOTENV_CONVENTION=flow dotenvx run -- node index.js
[[email protected]] injecting env (1) from .env.development.local, .env.development, .env.local, .env
Hello development localFurther, we recommend using DOTENV_ENV over NODE_ENV– as dotenvx works everywhere, not just node.
$ DOTENV_ENV=development dotenvx run --convention=flow -- node index.js
[[email protected]] injecting env (1) from .env.development.local, .env.development, .env.local, .env
Hello development localSpecify a custom private-key file when using file storage.
$ mkdir -p apps/app1
$ touch apps/app1/.env
$ dotenvx set HELLO World -fk .env.keys -f apps/app1/.env
$ dotenvx run -fk .env.keys -f apps/app1/.env -- yourcommandInject masked values into the command. By default, up to the first six characters are visible.
$ echo "SECRET=abcdefghijkl" > .env
$ echo "console.log(process.env.SECRET)" > index.js
$ dotenvx run --mask --quiet -- node index.js
abcdef******Pass a number to control how many characters are visible, such as --mask 0 to fully mask values.
Set Armor ⛨ token for retrieving armored private keys.
$ dotenvx run --token "$DOTENVX_ARMOR_TOKEN" -- yourcommandTurn off OS secret store lookups.
$ dotenvx run --no-native -- yourcommandTurn off Dotenvx Armor ⛨ features.
$ dotenvx run --no-armor -- yourcommandReturn a single environment variable's value.
$ echo "HELLO=World" > .env
$ dotenvx get HELLO
WorldReturn a masked environment variable value. By default, up to the first six characters are visible.
$ echo "SECRET=abcdefghijkl" > .env
$ dotenvx get SECRET --mask
abcdef******Pass a number to control how many characters are visible, such as --mask 0 to fully mask values.
Turn off OS secret store lookups for get.
$ dotenvx get HELLO --no-nativeTurn off Dotenvx Armor ⛨ features for get.
$ dotenvx get HELLO --no-armor
WorldIgnore specific error codes.
$ dotenvx get HELLO --ignore=MISSING_ENV_FILEIgnore multiple error codes by separating them with spaces.
$ dotenvx get HELLO --ignore=MISSING_ENV_FILE MISSING_KEYYou can also set DOTENV_IGNORE. Its value is a comma-separated list.
$ DOTENV_IGNORE=MISSING_ENV_FILE,OTHER dotenvx get HELLOReturn a single environment variable's value from a specific .env file.
$ echo "HELLO=World" > .env
$ echo "HELLO=production" > .env.production
$ dotenvx get HELLO -f .env.production
productionReturn a single environment variable's value from the .env file in a directory. This is useful with monorepos.
$ dotenvx get HELLO -f ../..
WorldSpecify a custom private-key file when using file storage.
$ mkdir -p apps/app1
$ touch apps/app1/.env
$ dotenvx set HELLO World -fk .env.keys -f apps/app1/.env
$ dotenvx get HELLO -fk .env.keys -f apps/app1/.env
worldReturn a single environment variable's value from a --env string.
$ dotenvx get HELLO --env HELLO=String -f .env.production
StringReturn a single environment variable's value where each found value is overloaded.
$ echo "HELLO=World" > .env
$ echo "HELLO=production" > .env.production
$ dotenvx get HELLO -f .env.production --env HELLO=String -f .env --overload
WorldExit with code 1 if any errors are encountered - like a missing key, missing .env file, or decryption failure.
$ dotenvx get DOES_NOT_EXIST --strict
[MISSING_KEY] missing key (DOES_NOT_EXIST)Return a single environment variable's value using Next.js' convention. Set --convention to nextjs:
$ echo "HELLO=development local" > .env.development.local
$ echo "HELLO=local" > .env.local
$ echo "HELLO=development" > .env.development
$ echo "HELLO=env" > .env
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
$ dotenvx get HELLO --convention=nextjs
development localYou can also set DOTENV_CONVENTION=nextjs.
$ DOTENV_CONVENTION=nextjs dotenvx get HELLO
development localReturn a single environment variable's value using Next.js' convention from a directory. This is useful with monorepos.
$ dotenvx get HELLO -f ../.. --convention=nextjs
development localReturn a single environment variable's value using dotenv-flow's convention. Set --convention to flow:
$ echo "HELLO=development local" > .env.development.local
$ echo "HELLO=development" > .env.development
$ echo "HELLO=local" > .env.local
$ echo "HELLO=env" > .env
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
$ NODE_ENV=development dotenvx get HELLO --convention=flow
development localYou can also set DOTENV_CONVENTION=flow.
$ NODE_ENV=development DOTENV_CONVENTION=flow dotenvx get HELLO
development localFurther, we recommend using DOTENV_ENV over NODE_ENV– as dotenvx works everywhere, not just node.
$ DOTENV_ENV=development dotenvx get HELLO --convention=flow
development localReturn a json response of all key/value pairs in a .env file.
$ echo "HELLO=World" > .env
$ dotenvx get
{"HELLO":"World"}Make the JSON output more readable.
$ echo "HELLO=World" > .env
$ dotenvx get --pretty-print
{
"HELLO": "World"
}Include only matching keys by passing --include-key. Glob patterns are supported.
$ echo "HELLO=World\nHOLA=Mundo\nGOODBYE=World" > .env
$ dotenvx get -ik "H*"
{"HELLO":"World","HOLA":"Mundo"}Exclude matching keys by passing --exclude-key. Glob patterns are supported.
$ echo "DOTENV_PUBLIC_KEY=public\nHELLO=World" > .env
$ dotenvx get --format=eval-export -ek "DOTENV_PUBLIC_KEY*"
export HELLO='World'Return a colon-formatted response of all key/value pairs in a .env file.
$ echo "HELLO=World" > .env
$ dotenvx get --format colon
HELLO: WorldReturn a shell formatted response of all key/value pairs in a .env file.
$ echo "HELLO=World" > .env
$ echo "KEY=value" >> .env
$ dotenvx get --format shell
HELLO=World KEY=valueThis can be useful when combined with env on the command line.
$ echo "console.log('Hello ' + process.env.KEY + ' ' + process.env.HELLO)" > index.js
$ env $(dotenvx get --format=shell) node index.js
Hello value Worldor with export.
$ echo "console.log('Hello ' + process.env.KEY + ' ' + process.env.HELLO)" > index.js
$ export $(dotenvx get --format=shell)
$ node index.js
Hello value WorldReturn an eval-ready shell formatted response of all key/value pairs in a .env file.
$ echo "HELLO=World" > .env
$ echo "KEY=value" >> .env
$ dotenvx get --format eval
HELLO="World"
KEY="value"Note that this exports newlines and quoted strings.
This can be useful for more complex .env values (spaces, escaped characters, quotes, etc) combin

