Dotenv.toml Quickstart

Create your first Dotenv.toml

Dotenv.toml

Create

Install Dotenvx, then start with a .env file.


# .env
PORT=3000
DATABASE_URL="postgres://localhost/myapp"

Create a file named Dotenv.toml in your project root.


# Dotenv.toml
strict = true

[env.PORT]
type = "port"
required = true
storage = "plaintext"

[env.DATABASE_URL]
type = "url"
required = true
storage = "encrypted"
redacted = true

Both variables are required explicitly. PORT stays readable. DATABASE_URL is selected for encrypted storage and output redaction. strict = true stops your command when a value-validation rule fails.

Encrypt


$ dotenvx encrypt

Dotenvx encrypts DATABASE_URL and leaves PORT readable. Keep your private key separate from Git.

Run

Dotenvx validates resolved values before running your app.


$ dotenvx run -- node index.js

Replace node index.js with your app's command. Try PORT=not-a-port in .env to see strict validation stop startup. Change it back to 3000.

The app receives the real database URL. Dotenvx redacts it in matching terminal output. Commit Dotenv.toml alongside the encrypted .env file.

Read the full Dotenv.toml spec →

markdown