Star on GitHub - 5.8k

← back to blog

Dotenv 18: CLI

Scott Motte ·

Its the biggest change to Dotenv in a decade. Dotenv now has a CLI.

Usage

Install [email protected] or greater.

$ npm install dotenv --save

Create your .env file.

# .env
HELLO="World"

And your app (below is a very simple hello world).

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

And then use it with the dotenv run command.

$ npx dotenv run -- node index.js
◇ injected env (1) from .env
Hello World

That’s it!

Dotenv started with a simple idea: load your .env file and get to work. The CLI brings that same simplicity to any command - whether you run it yourself or an agent runs it for you. A small command, and a big next step for dotenv.