Env Vars Cheatsheet - .env Config & dotenv Usage

Almost every Node/Python/frontend project writes a .env, yet the most common traps are spaces around the equals sign, a # inside a value treated as a comment, and secrets accidentally committed to the repo. This reference covers 5 groups: variable definition, reading in Shell/Node/Python, dotenv loader usage, multi-environment file layout (.env/.env.local/.env.production), and a set of security-pitfall reminders. Sanity-check the format after writing and confirm no secrets were committed before deploying. After reading you can organize environment variables cleanly and avoid the most common leakage issues.

Config Formats·24 commands·Last updated 2026-08-02
envdotenvEnvironment Variablesconfig.env

Definition 6

KEY=value
Define a variable (no spaces around =)
KEY="value with space"
Quote values with spaces or special chars
KEY='literal $NOT_EXPANDED'
Single quotes: no variable expansion
KEY=${OTHER}_suffix
Double quotes: reference other variables
# comment
Hash starts a comment line
export KEY=value
Set and export as an environment variable

Reading 5

echo $KEY
Read in shell (Linux/macOS)
echo %KEY%
Read in Windows cmd
$env:KEY
Read in PowerShell
process.env.KEY
Read in Node.js
os.getenv("KEY")
Read in Python

dotenv Usage 4

require('dotenv').config()
Node: load .env into process.env
import 'dotenv/config'
ESM import to load .env
dotenv.config({ path: '.env.local' })
Load with a custom file path
python-dotenv load_dotenv()
Python: load .env

Multi-environment Files 5

.env
Default env (don't commit to git)
.env.local
Local override (higher priority)
.env.development
Development env
.env.production
Production env
.env.example
Example template, committable, no real secrets

Security FAQ 4

Don't commit secrets
Don't commit secrets
Case sensitive
Case sensitive
Type conversion
Type conversion
Escape newlines
Escape newlines

Tips

  • No spaces around = (KEY=value is correct, KEY = value is wrong).
  • Add .env to .gitignore; commit secrets via .env.example template instead.
  • All values are strings; convert numbers with Number()/parseInt().
  • Multi-line values use quotes or \n for newlines.

Official References

Each command links to its official documentation below, so you can verify the latest usage and read deeper.

Maintained by LaoHand

Publicly updated on Aug 2, 2026, continuously proofread against official docs.

Contact Us

Wrong command or description? Send us corrections, business inquiries or product feedback by email.

Contact Us