What do you do when dealing with confidential information? I will summarize things like.
--Do not save confidential information in the code as it is
--It is put together in .env
, but when saving it in git, it is often set to .env.sample
except for confidential information.
--There are packages that handle .env
in many languages
There is confidential information in the application that you do not want to show to a third party, such as "DB information", "server information", and "external API linkage information". Confidential information stores information as an environment variable separately from the code.
There are multiple projects locally, and I want to handle different environment variables for each project. Also, I would like to put together an environment variable configuration file for new members.
Therefore, create a file that summarizes confidential information as a .env file
and manage the information.
If you put the .env file
as it is on git, confidential information will be put on git, so you often add the .env file
to .gitignore
and put a sample file called .env.sample
.
A simple summary of how to add / view / delete environment variables.
#Setting environment variables
$ export GERU="mew" #Put the value "mew" in the environment variable named GERU
#Checking environment variables
$ echo $GERU #View the contents of an environment variable named GERU
mew
#Check the set environment variables
$ printenv #Check all the set environment variables
...
GERU=mew
...
#Delete the set environment variable
$ unset GERU #Delete the set environment variable
$ echo $GERU #Since the setting has been deleted, it is not displayed even if it is output
-To set environment variables -To define or delete shell variables
Packages that handle environment variables in .env have been developed and used in various languages.
Ruby[dotenv]
Javascript[dotenv]
Python[python-dotenv]
--Do not save confidential information in the code as it is
--It is put together in .env
, but when saving it in git, it is often set to .env.sample
except for confidential information.
--There are packages that handle .env
in many languages
Recommended Posts