Dotenvxfile

Create your first Dotenvxfile.

Create

Install Dotenvx, then start with a .env file:

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

Create a file named Dotenvxfile in your project root:

# Dotenvxfile
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: strict validation stops the command. Change it back to 3000.

The app receives the real database URL; matching terminal output is redacted automatically. Commit your Dotenvxfile alongside the encrypted .env file.

Read the full Dotenvxfile spec →

Open page ↗

Side path