Written by
Edd Turtle
on gophercoding.com
on
on
(Updated: )
Using a .env File & Environment Variables
Environment variables are used throughout the coding ecosystem as a way of keeping secrets out of the code. They’re also useful as a way of keeping the code the same between environments, e.g. live, uat and test servers but functionality might work differently.
This post sets out to explain the basics of getting these variables, setting them and easily using your own when in your local environment.
Basics: Get & Set
|
|
From .env file:
Run:
|
|
Create your .env file in the root of your project:
|
|
Read from environment file. This uses the pre-made autoload file to load in a .env file - if it exists. This is useful, as you may have a .env file for local development and not in production systems.
|
|