Introductory information on environment variables and how to set them.
In software development, an "environment" is the context in which a program or process runs.
An environment variable is a value that adjusts the environment (the process) in some way.
For example, consider some variable whose value you want to be different when developing locally versus running in production. Although you could achieve that by writing a conditional in your code, it's much easier (and a better practice) to use an environment variable. Here's and example in a Node.js application:
const myVar = isProduction ? "thisValue" : "thatValue"
const myVar = process.env.MY_VAR
You can set environment variables in a number of ways, and those depend on the system in which the process is running. The action is often performed on the command line, but many programming languages have mechanisms and libraries for making this process easier for you.
Because environment variables are specific to the environment and not the code, they are a great way to store sensitive values for your processes.
To dig into more technical details and theory, read the Wikipedia entry.
Otherwise, move on to When to Use Environment Variables and then do a bit of research into how to set environment variables in the language you're using.
Environment variables can seem like overkill to new developers, but there are two scenarios in which they are extremely beneficial to efficiency and security.Jan 14, 2019