Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages

Free tool · Developer tools

.env file generator

Type your variables as NAME=value lines and get a clean .env file plus a .env.example with the values removed. The sample text holds 9 variables, quotes 1 value that needs it and leaves 1 empty for you to fill.

  • Free
  • No sign-up
  • Runs in your browser

By Maaz Zindani · Updated

Lines that start with # are kept as comments. A name alone gives an empty value.
Options
Your .env file

9 variables1 value quoted, 1 empty value

  • No problems found
.env
# App
APP_ENV=production
APP_PORT=3000
APP_URL=https://example.com

# Database
DB_HOST=localhost
DB_PORT=5432
DB_NAME=shop
DB_USER=shop_app
DB_PASSWORD="p@ss word #1"

# Secrets
SESSION_SECRET=
.env.example
# App
APP_ENV=
APP_PORT=
APP_URL=

# Database
DB_HOST=
DB_PORT=
DB_NAME=
DB_USER=
DB_PASSWORD=

# Secrets
SESSION_SECRET=

How to use the .env File Generator

  1. Type or paste your variables, one NAME=value per line, or add a starter set such as the database or email names.
  2. Press Fill empty secrets to write a random 64 character value into every empty name that holds SECRET, KEY, TOKEN, PASSWORD or SALT.
  3. Choose the options: keep comments, sort the names, upper case them, or quote every value.
  4. Copy or download the .env file, and the .env.example to share with your team.

How is a .env file written?

A .env file is a plain text list with one NAME=value pair on each line. Names use letters, digits and the _ character and do not start with a digit, and a line that starts with # is a comment. This page checks each name, so 2B=x is reported with its line number instead of being passed on to your app.

Values need care. The dotenv README says a # starts a comment unless the value is quoted, so a password with a hash must be wrapped in quotes, and a quoted value keeps the spaces at both ends while an unquoted one is trimmed. The generator adds the quotes for you. An unquoted value is cut at a space followed by #, because dotenv reads the rest as a comment, and the page tells you when it does that. In the sample, the password p@ss word #1 contains a space and a hash, so it is typed in quotes and written as DB_PASSWORD="p@ss word #1", and the other 8 values stay bare.

If a value already holds a double quote, the page switches to single quotes, and to backticks if both are present. A value that holds all three marks is left unquoted and flagged so you can change it by hand.

How six typed values are written
You typeWritten in .envQuoted
30003000No
https://example.comhttps://example.comNo
p@ss word #1"p@ss word #1"Yes
say "hi"'say "hi"'Yes
it's "quoted"`it's "quoted"`Yes
(empty)(empty)No

What is a .env.example file for?

The dotenv README advises against committing the real .env file, because it holds passwords and keys. The usual answer is a second file with the same names and no values, which is safe to share and shows a new teammate what to fill in. The generator builds it at the same time from the same lines, so the two files never drift apart.

For the sample, .env.example has 9 lines that end in an equals sign, and the comments are kept so the groups stay readable. Add .env to your ignore file and commit .env.example. The two outputs have their own copy and download buttons.

The starter sets you can add with one click
Starter setNamesFirst names
Web app4APP_ENV, APP_PORT, APP_URL
Database5DB_HOST, DB_PORT, DB_NAME
Email (SMTP)5SMTP_HOST, SMTP_PORT, SMTP_USER
Auth secrets3SESSION_SECRET, JWT_SECRET, ENCRYPTION_KEY
Object storage4STORAGE_BUCKET, STORAGE_REGION, STORAGE_ACCESS_KEY

How do I fill secrets and keep the file tidy?

Fill empty secrets looks for names that contain SECRET, KEY, TOKEN, PASSWORD or SALT and an empty value. In a four line test it filled 2 lines, DB_PASSWORD and JWT_SECRET, and skipped API_KEY because it already had a value and APP_PORT because it is not a secret name. Each fill is 32 random bytes shown as 64 hex characters, made by the browser's own random number source, and it is never sent anywhere.

Sorting from A to Z puts the names in order but removes comments and blank lines, because a comment belongs to the group below it and would end up in the wrong place. Upper case names turns db_host into DB_HOST. Quote every value wraps all non empty values, which gives 8 quoted values for the sample against 1 by default and 9 names in the sorted output.

Duplicate names are listed with both line numbers, for example A appears on lines 1 and 3. Keep one of them. Loaders do not all treat repeats the same way. This page writes text only and does not check what your app does with the values.

Use it with

Questions

How do I create a .env file?

Make a plain text file named .env with one NAME=value pair per line, such as APP_PORT=3000. Paste your lines here and the page quotes values where needed, so you get 9 clean lines from the sample.

When does a value need quotes in a .env file?

When it holds a space, a #, or a quote mark. The dotenv README says a # starts a comment unless the value is quoted, and quoted values keep their surrounding spaces.

What is the difference between .env and .env.example?

.env holds the real values and stays private. .env.example has the same names with empty values and is safe to commit, so others know which variables to set.

Should I commit my .env file?

The dotenv README answers no. Commit .env.example and keep .env in your ignore file.

How are the random secrets made?

With the browser crypto random source, 32 bytes at a time, shown as 64 hex characters. They stay in this page until you copy or download them.

Is my text uploaded?

No. The lines you type are processed in your browser and are not sent or stored.

The tool's results are computed in your browser by the code on this page, using the sources listed above; the explanations are checked against the tool's own output.