Environment variables are used to store sensitive information securely π
In simple words
Environment variables keep important data
outside your source code π§
Without environment variables β
β’ API keys get exposed
β’ Passwords leak
β’ Security risks increase
π What is Stored in Environment Variables
β’ API keys π
β’ Database URLs ποΈ
β’ Secret tokens πͺ
β’ Passwords π
β’ Port numbers π
π Real World Usage
β’ Connecting backend to database
β’ Using payment gateways
β’ Authenticating third party APIs
β’ Deploying apps securely
π Common Environment Files
β’
.env β’
.env.local β’
.env.production π» Example: Using Environment Variables in Node
require("dotenv").config();
const PORT = process.env.PORT;
const DB_URL = process.env.DB_URL;
app.listen(PORT, () => {
console.log("Server running");
});