Home

WTF is an Environment Variable?

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:

// bad
const myVar = isProduction ? "thisValue" : "thatValue"

// good
const myVar = process.env.MY_VAR

Setting Environment Variables

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.

Storing Sensitive Information

Because environment variables are specific to the environment and not the code, they are a great way to store sensitive values for your processes.

Further Reading

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.

Let's Connect

Keep Reading

WTF is Node.js?

An brief introduction to Node.js, along with links to dig in further with a tutorial or course.

Jun 29, 2020

When to Use Environment Variables

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

WTF is Jest?

Learn the basics of the JavaScript testing framework, Jest.

Aug 23, 2021