Logo

Format

Format existing .env files, quoting unquoted values and standardizing structure.


Formatting Environment Files (format / fmt)

The format command formats your existing .env files. It wraps values in quotes (e.g. converting NEXT_PUBLIC_BASE_URL=http://localhost:3000 to NEXT_PUBLIC_BASE_URL="http://localhost:3000"), normalizes spacing, and preserves comments, inline comments, and blank lines.

bash
envnix format

By default, running envnix format reads your .env file and outputs the formatted result to .env.formatted.

In-Place Formatting (--write / -w or --force / -f)

To format the original .env file directly in-place:

bash
envnix format --write # or envnix format --force

Options

OptionShorthandDescription
--write-wFormat directly in-place (overwrites the input file)
--force-fAlias for --write
--input <file>-iCustom input file instead of the default .env
--output <file>-oCustom output file path
--all-aFormat all matched .env* files in the directory
--quotes <mode>Quotes mode: always (default), as-needed, or never
--quote-type <type>Quote type: double (default) or single
--sort [asc|desc]Sort variables alphabetically (keeps comments attached)
--no-sortDisable sorting
--no-commentsStrip comments from output
--dry-runPrint formatted output to stdout without modifying disk
--checkCheck if input files are formatted (for CI environments)
--verbosePrint verbose logs
--quiet-qOnly output errors

Example Usage

Given an input .env file:

env
# API & server configuration PORT=3000 NEXT_PUBLIC_BASE_URL=http://localhost:3000 # Frontend base URL API_SECRET='super-secret-token' EMPTY=

Running envnix format --write produces:

env
# API & server configuration PORT="3000" NEXT_PUBLIC_BASE_URL="http://localhost:3000" # Frontend base URL API_SECRET="super-secret-token" EMPTY=""

Format All Environment Files

To format all .env* files in your project directory in-place:

bash
envnix format --all --write

CI Formatting Check

Check if all environment files are properly formatted in your CI workflows:

bash
envnix format --check

How is this guide?

Last updated on October 24, 2026