Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dotenv/dotenv

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dotenv/dotenv

a better dotenv–from the creator of `dotenv`

  • 0.2.19
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
2
Weekly downloads
 
Created
Source

dotenv.org

a better dotenv–from the creator of dotenv.

  • run anywhere (cross-platform)
  • multi-environment
  • encrypted envs

 

Quickstart

brew install dotenv-org/brew/dotenv

 

Run Anywhere

$ echo "HELLO=World" > .env && echo "console.log('Hello ' + process.env.HELLO)" > index.js

$ node index.js
Hello undefined

$ dotenv run -- node index.js
Hello World
> :-D

More examples

  • Python 🐍
    $ echo 'import os;print("Hello " + os.getenv("HELLO", ""))' > index.py
    
    $ dotenv run -- python3 index.py
    Hello World
    
  • PHP 🐘
    $ echo '<?php echo "Hello {$_SERVER["HELLO"]}\n";' > index.php
    
    $ dotenv run -- php index.php
    Hello World
    
  • Ruby 💎
    $ echo 'puts "Hello #{ENV["HELLO"]}"' > index.rb
    
    $ dotenv 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
    
    $ dotenv run -- cargo run
    Hello World
    
  • Frameworks ▲
    $ dotenv run -- next dev
    $ dotenv run -- npm start
    $ dotenv run -- bin/rails s
    $ dotenv run -- php artisan serve
    
  • Docker 🐳
    # run as a command-line tool
    docker run -it --rm -v $(pwd):/app dotenv/dotenv run -- node index.js
    
    # include in a Dockerfile
    # example coming soon
    
  • CI/CDs 🐙
    examples coming soon
    
  • Platforms
    examples coming soon
    
  • npx
    # alternatively use npx
    $ npx @dotenv/dotenv run -- node index.js
    $ npx @dotenv/dotenv run -- next dev
    $ npx @dotenv/dotenv run -- npm start
    
  • Git
    # use as a git submodule
    $ git dotenv run -- node index.js
    $ git dotenv run -- next dev
    $ git dotenv run -- npm start
    

 

Multiple Environments

Pass the --env-file flag (shorthand -f) to run any environment from a .env.environment file.

$ dotenv run --env-file=.env.production -- node index.js
[dotenv][INFO] Injecting 12 production environment variables into your application process

Combine multiple .env files if you like.

$ dotenv run --env-file=.env.local --env-file=.env -- node index.js
[dotenv][INFO] Injecting 12 local, 1 development environment variables into your application process

 

Encrypt Your Env Files

WIP

 

Usage

Guide

Begin by creating a simple 'hello world' program.

// index.js
console.log(`Hello ${process.env.HELLO}`)

Run it.

$ node index.js
Hello undefined

Run it with dotenv.

$ dotenv run -- node index.js
[dotenv@x.x.x][WARN] ENOENT: no such file or directory, open '/../../.env'
Hello undefined

It 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.

$ dotenv run -- node index.js
[dotenv@x.x.x][INFO] Injecting 0 environment variables into your application process
Hello undefined

Hrm, still undefined. Pass the --debug flag to debug the issue. I'll give you a hint: 🍮

$ dotenv run --debug -- node index.js
[dotenv@x.x.x][VERBOSE] Loading env from /Users/scottmotte/Code/dotenv-org/temp/sandbox2/.env
[dotenv@x.x.x][DEBUG] Reading env from /Users/scottmotte/Code/dotenv-org/temp/sandbox2/.env
[dotenv@x.x.x][DEBUG] Parsing env from /Users/scottmotte/Code/dotenv-org/temp/sandbox2/.env
[dotenv@x.x.x][DEBUG] {"JELLO":"World"}

# Oops, HELLO not JELLO ^^

Fix your .env file.

# .env
HELLO="World"

One last time. Le tired.

$ dotenv run -- node index.js
[dotenv@x.x.x][INFO] Injecting 0 environment variables into your application process
Hello undefined

 

Install

Installing with brew is most straight forward:

brew install dotenv-org/brew/dotenv

Other Ways to Install

  1. After brew, installing globally using npm is easiest:
npm install @dotenv/dotenv --global
  1. Or use with npx:
npx @dotenv/dotenv help
  1. dotenv is a standalone binary, so (if you want) you can just download it directly:
# download it to `./dotenv`
curl -Lo ./dotenv --compressed -f --proto '=https' https://github.com/dotenv-org/dotenv/releases/latest/download/dotenv-$(uname)-$(uname -m).tar.gz

# install it to `/usr/local/bin/dotenv`
sudo install -m 755 dotenv /usr/local/bin

# check it works
dotenv --help

Contributing

If you have questions or feedback:

Keywords

FAQs

Package last updated on 20 Nov 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc