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.
Definition 6
KEY=valueKEY="value with space"KEY='literal $NOT_EXPANDED'KEY=${OTHER}_suffix# commentexport KEY=valueReading 5
echo $KEYecho %KEY%$env:KEYprocess.env.KEYos.getenv("KEY")dotenv Usage 4
require('dotenv').config()import 'dotenv/config'dotenv.config({ path: '.env.local' })python-dotenv load_dotenv()Multi-environment Files 5
.env.env.local.env.development.env.production.env.exampleSecurity FAQ 4
Don't commit secretsCase sensitiveType conversionEscape newlinesTips
- 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