﻿# Dotenv 18: CLI

 Scott Motte · September 19, 2026

It's the biggest change to Dotenv in a decade, a CLI.

For years, dotenv has loaded your .env file from inside your application. Now it can load those variables before your command starts. Your app just reads its environment.

That makes the same .env file useful for scripts, tests, and other command-line tools, too. And it gives coding agents a simple way to run a command with the environment it needs.

   Download the [mp4](https://github.com/user-attachments/assets/79395e92-5ce0-430d-b8b5-31631aac25bb) video.

 Dotenv CLI in action

## Usage

Install [dotenv@18.0.0](https://github.com/motdotla/dotenv) or greater.

```cli
$ npm install dotenv --save
```

Create your .env file.

```dotenv
# .env
HELLO="World"
```

Create a simple app. There's no dotenv import needed here.

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

Run it with the new CLI.

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

That's it. Dotenv loads .env, then starts Node with those variables available. The command after the -- can be any executable available on your PATH.

## Choose your environment

By default, the CLI reads .env. To use another file, pass -f:

```cli
$ npx dotenv run -f .env.local -- node index.js
```

Variables already set in your environment take precedence. Add --override if you want the file's values to win instead.

## Upgrading

The familiar `require('dotenv').config()` API is still here. If you used Node's -r dotenv/config preload, switch to the CLI command above. Version 18 also removes the legacy .env.vault format; use [dotenvx](/) for encrypted .env files.

There's an optional faster parser, too: add --fast to your CLI command to try it. See the [release notes](https://github.com/motdotla/dotenv/blob/master/CHANGELOG.md#1800-2026-09-17) for the full changes.

## A small command, a big step

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.

## Subscribe

A newsletter on making .env – from the creator of dotenv

[Subscribe](/newsletter/)

Unsubscribe any time.

 [Back to blog](/blog/) [Subscribe via RSS](/feed.xml)
