Environment Variables Explained
There are two fundamental components in any given computer programming languages and they are variable and constants. Variable and constants plays a role in where they represent unique memory locations that contains a data in the program. The only difference in the two is that variables values are changeable during execution but constants cannot be reassigned.
Environment variable is where a variable that has a value outside the program but has built into the operating system. AN environment variable is made with name and value pair.
Environment Variables in the dotenv Package
Dotenv is a zero-dependency module that loads environment variables from a .env file into process.env . Storing…
“Dotenv is a zero-dependency module that loads environment variables from a
.env file into
process.env. Storing configuration in the environment separate from code is based on The Twelve-Factor App methodology.”
With this package you can utilize it through the front end and the back end. Using this package is very simple, first you install by
npm install dotenv
Add this to the top of your application
What this does is externalize data by moving it from the source code into the environment variable in a .
env file. However if you were to make this public it would also be best to add a
.gitignore file, that way when you
git push it prevents the .env file from showing. I have provided a layout link for most gitignore
Dotenv makes it very simple to allow you to create secret keys that your application needs to function and keep them from going public.