Dotenvx
a secure dotenv–from the creator of `dotenv`
Install / Use
/learn @dotenvx/DotenvxREADME
a secure dotenv–from the creator of dotenv.
- run anywhere (cross-platform)
- multi-environment
- encrypted envs
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!
<details><summary>with npm 🌍</summary><br>npm i -g @dotenvx/dotenvx
dotenvx encrypt
</details> <details><summary>with curl 🌐</summary><br>
curl -sfS https://dotenvx.sh | sh
dotenvx encrypt
</details> <details><summary>with brew 🍺</summary><br>
brew install dotenvx/brew/dotenvx
dotenvx encrypt
</details> <details><summary>with docker 🐳</summary><br>
docker run -it --rm -v $(pwd):/app dotenv/dotenvx encrypt
</details> <details><summary>with github releases 🐙</summary><br>
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
</details> <details><summary>or windows 🪟</summary><br>
winget install dotenvx
dotenvx encrypt
</details>
Run Anywhere
$ echo "HELLO=Dotenvx" > .env
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
$ node index.js
Hello undefined # without dotenvx
$ dotenvx run -- node index.js
Hello Dotenvx # with dotenvx
> :-D
More examples
<details><summary>TypeScript 📘</summary><br>// 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=Dotenvx" > .env
$ dotenvx run -- npx tsx index.ts
Hello Dotenvx
</details>
<details><summary>Deno 🦕</summary><br>
$ echo "HELLO=Dotenvx" > .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 Dotenvx
</details> <details><summary>Bun 🥟</summary><br>[!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=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
</details>
<details><summary>Python 🐍</summary><br>
$ echo "HELLO=Dotenvx" > .env
$ echo 'import os;print("Hello " + os.getenv("HELLO", ""))' > index.py
$ dotenvx run -- python3 index.py
Hello Dotenvx
</details>
<details><summary>PHP 🐘</summary><br>
$ echo "HELLO=Dotenvx" > .env
$ echo '<?php echo "Hello {$_SERVER["HELLO"]}\n";' > index.php
$ dotenvx run -- php index.php
Hello Dotenvx
</details>
<details><summary>Ruby 💎</summary><br>
$ echo "HELLO=Dotenvx" > .env
$ echo 'puts "Hello #{ENV["HELLO"]}"' > index.rb
$ dotenvx run -- ruby index.rb
Hello Dotenvx
</details>
<details><summary>Go 🐹</summary><br>
$ echo "HELLO=Dotenvx" > .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 Dotenvx
</details>
<details><summary>Rust 🦀</summary><br>
$ echo "HELLO=Dotenvx" > .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 Dotenvx
</details>
<details><summary>Java ☕️</summary><br>
$ echo "HELLO=Dotenvx" > .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 Dotenvx
</details>
<details><summary>Clojure 🌿</summary><br>
$ echo "HELLO=Dotenvx" > .env
$ echo '(println "Hello" (System/getenv "HELLO"))' > index.clj
$ dotenvx run -- clojure -M index.clj
Hello Dotenvx
</details>
<details><summary>Kotlin 📐</summary><br>
$ echo "HELLO=Dotenvx" > .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 Dotenvx
</details>
<details><summary>.NET 🔵</summary><br>
$ dotnet new console -n HelloWorld -o HelloWorld
$ cd HelloWorld
$ echo "HELLO=Dotenvx" | Out-File -FilePath .env -Encoding utf8
$ echo 'Console.WriteLine($"Hello {Environment.GetEnvironmentVariable("HELLO")}");' > Program.cs
$ dotenvx run -- dotnet run
Hello Dotenvx
</details>
<details><summary>Bash 🖥️</summary><br>
$ echo "HELLO=Dotenvx" > .env
$ dotenvx run --quiet -- sh -c 'echo Hello $HELLO'
Hello Dotenvx
</details>
<details><summary>Fish 🐠</summary><br>
$ echo "HELLO=Dotenvx" > .env
$ dotenvx run --quiet -- sh -c 'echo Hello $HELLO'
Hello Dotenvx
</details>
<details><summary>Cron ⏰</summary><br>
# run every day at 8am
0 8 * * * dotenvx run -- /path/to/myscript.sh
</details>
<details><summary>Frameworks ▲</summary><br>
$ dotenvx run -- next dev
$ dotenvx run -- npm start
$ dotenvx run -- bin/rails s
$ dotenvx run -- php artisan serve
see framework guides
</details> <details><summary>Docker 🐳</summary><br>$ docker run -it --rm -v $(pwd):/app dotenv/dotenvx run -- node index.js
Or in any image:
FROM node:latest
RUN echo "HELLO=Dotenvx" > .env && echo "console.log('Hello ' + process.env.HELLO)" > index.js
RUN curl -fsS https://dotenvx.sh/install.sh | sh
CMD ["dotenvx", "run", "--", "echo", "Hello $HELLO"]
see docker guide
</details> <details><summary>CI/CDs 🐙</summary><br>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 }}
</details>
<details><summary>Platforms</summary><br>
# heroku
heroku buildpacks:add https://github.com/dotenvx/heroku-buildpack-dotenvx
# docker
RUN curl -fsS https://dotenvx.sh/install.sh | sh
# vercel
npm install @dotenvx/dotenvx --save
see platform guides
</details> <details><summary>Process Managers</summary><br>// pm2
"scripts": {
"start": "dotenvx run -- pm2-runtime start ecosystem.config.js --env production"
},
</details>
<details><summary>npx</summary><br>
# alternatively use npx
$ npx @dotenvx/dotenvx run -- node index.js
$ npx @dotenvx/dotenvx run -- next dev
$ npx @dotenvx/dotenvx run -- npm start
</details>
<details><summary>npm</summary><br>
$ 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
[dotenvx@1.X.X] injecting env (1) from .env.production
Hello Dotenvx
</details>
<details><summary>asdf</summary><br>
# use dotenvx with asdf
$ asdf plugin add dotenvx
$ asdf install dotenvx latest
thank you @jgburet of Paris 🇫🇷
</details> <details><summary>Git</summary><br># use as a git submodule
$ git dotenvx run -- node index.js
$ git dotenvx run -- next dev
$ git dotenvx run -- npm start
</details>
<details><summary>Variable Expansion</sum
