An environment variable is a key-value pair provided to a process by its surrounding environment, such as the shell, container or hosting platform, instead of being written into the source code. Programs read them at startup to learn their settings.
Why it matters
Keeping configuration out of code lets the same build run in development, staging and production with different settings. It also keeps secrets such as database passwords and API keys out of version control. Hosting dashboards, Docker and CI/CD systems all provide ways to set them.
Example
$ export DATABASE_URL="postgres://app:secret@db:5432/shop"
$ node server.js
const url = process.env.DATABASE_URL;
const port = process.env.PORT || 3000;
If PORT is not set, the code falls back to 3000.
Common mistakes
- Committing a
.envfile that holds real secrets to the repository. - Forgetting to set the variable on the server after deploying, so the app starts with a missing value.
- Printing all variables in logs or error pages, which leaks credentials.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.