Skip to content
AITermsLab
–points–day streak

What is a .env file?

A .env file is a small file in a project that holds environment variables, like secret keys, on your own computer. It must never be shared or uploaded.

Last updated

In real life

Like the note with your safe's combination: useful at home, dangerous if it's ever pinned to a noticeboard.

Try it yourself

The demo has a made-up project with a .env file holding a secret key. Push it to a public repository without a .gitignore rule and the key is exposed to anyone. List .env in .gitignore, push again, and the key stays on your laptop.

Your laptop: the rosas-bakery project

  • index.html
  • style.css
  • app.js
  • .env

Inside .env

EMAIL_API_KEY=secret_4b8e17aa92

On GitHub (anyone can see)

Nothing pushed yet.

A .env file keeps secrets on your own computer. Listing it in .gitignore tells Git never to upload it. Try pushing with the switch off, then on.

.env file vs environment variable

An environment variable is a setting your code reads. A .env file is one way to store those settings on your own computer. Live sites keep them in the host's settings instead.

What is an environment variable?

Common questions

What is .gitignore?

A file listing things Git should never track or upload, like .env and large build folders. Most project templates add .env to it for you.

I uploaded my .env by mistake. What now?

Deleting the file isn't enough, because Git keeps the history. Revoke every key in it straight away, make new ones, then remove the file.

Where you will use this

Quick check: .env file

Question 1 of 3

What does a .env file hold?

What does a .env file hold?