Package Exports
- @dotenvx/dotenvx
- @dotenvx/dotenvx/src/lib/main.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@dotenvx/dotenvx) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme

a better dotenv–from the creator of dotenv.
- run anywhere (cross-platform)
- multi-environment
- encrypted envs
Quickstart
brew install dotenvx/brew/dotenvx
Run Anywhere
$ echo "HELLO=World" > .env && echo "console.log('Hello ' + process.env.HELLO)" > index.js
$ node index.js
Hello undefined
$ dotenvx run -- node index.js
Hello World
> :-DMore examples
Python 🐍
$ echo 'import os;print("Hello " + os.getenv("HELLO", ""))' > index.py $ dotenvx run -- python3 index.py Hello World
PHP 🐘
$ echo '<?php echo "Hello {$_SERVER["HELLO"]}\n";' > index.php $ dotenvx run -- php index.php Hello World
Ruby 💎
$ echo 'puts "Hello #{ENV["HELLO"]}"' > index.rb $ dotenvx run -- ruby index.rb Hello World
Rust 🦀
$ 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
Java ☕️
$ 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
.NET 🔵
$ dotnet new console -n HelloWorld -o HelloWorld $ cd HelloWorld $ echo 'Console.WriteLine($"Hello {Environment.GetEnvironmentVariable("HELLO")}");' > Program.cs && echo "HELLO=World" > .env $ dotenvx run -- dotnet run Hello World
Frameworks ▲
$ dotenvx run -- next dev $ dotenvx run -- npm start $ dotenvx run -- bin/rails s $ dotenvx run -- php artisan serveDocker 🐳
$ docker run -it --rm -v $(pwd):/app dotenv/dotenvx run -- node index.js
Or 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/ | sh CMD ["dotenvx", "run", "--", "echo", "Hello $HELLO"]
CI/CDs 🐙
examples coming soon
Platforms
examples coming soon
npx
# alternatively use npx $ npx @dotenvx/dotenvx run -- node index.js $ npx @dotenvx/dotenvx run -- next dev $ npx @dotenvx/dotenvx run -- npm start
npm
$ 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][INFO] injecting 1 environment variable from .env Hello World
Git
# use as a git submodule $ git dotenvx run -- node index.js $ git dotenvx run -- next dev $ git dotenvx run -- npm start
Multiple Environments
Pass the --env-file flag (shorthand -f) to run any environment from a .env.environment file.
$ dotenvx run --env-file=.env.production -- node index.js
[dotenvx][INFO] injecting 12 environment variables from .env.productionCombine multiple .env files if you like.
$ dotenvx run --env-file=.env.local --env-file=.env -- node index.js
[dotenvx][INFO] injecting 13 environment variables from .env.local,.env
Encrypt Your Env Files
$ dotenvx encryptThis will encrypt your
.envfile to a.env.vaultfile. Commit your.env.vaultfile safely to code. This will also generate a.env.keysfile. Do NOT commit this file to code. Keep your.env.keyssecret. 🤫
Usage
Guide
Begin by creating a simple 'hello world' program.
// index.js
console.log(`Hello ${process.env.HELLO}`)Run it.
$ node index.js
Hello undefinedRun it with dotenvx.
$ dotenvx run -- node index.js
[dotenvx][WARN] ENOENT: no such file or directory, open '/../../.env'
Hello undefinedIt warns you when there is no .env file (pass the --quiet flag to suppress these warnings).
Create the .env file.
# env
JELLO="World"Run it again.
$ dotenvx run -- node index.js
[dotenvx][INFO] injecting 0 environment variables from .env
Hello undefinedHrm, still undefined. Pass the --debug flag to debug the issue. I'll give you a hint: 🍮
$ dotenvx run --debug -- node index.js
[dotenvx][VERBOSE] Loading env from /../../.env
[dotenvx][DEBUG] Reading env from /../../.env
[dotenvx][DEBUG] Parsing env from /../../.env
[dotenvx][DEBUG] {"JELLO":"World"}
# Oops, HELLO not JELLO ^^Fix your .env file.
# .env
HELLO="World"One last time. Le tired.
$ dotenvx run -- node index.js
[dotenvx][INFO] injecting 1 environment variable from .env
Hello World🎉 It worked!
Install
Installing with brew is most straight forward:
brew install dotenvx/brew/dotenvxOther Ways to Install
1. global npm
After brew, installing globally using npm is easiest:
npm install @dotenvx/dotenvx --global2. local npm
Or install in your package.json:
npm i @dotenvx/dotenvx --save{
"scripts": {
"start": "./node_modules/.bin/dotenvx run -- node index.js"
},
"dependencies": {
"@dotenvx/dotenvx": "^0.6.0"
}
}3. standalone binary
Or download it directly as a standalone binary:
# download it to `/user/local/bin/dotenvx`
curl -fsS https://dotenvx.sh/ | sh
# check it works
dotenvx helpContributing
If you have questions or feedback:
- github.com/dotenvx/dotenvx - bugs and discussions
- @dotenvx 𝕏 (DMs are open)