When using .env files to store API credential, is it better to store them as strings with quotation marks or as unquoted? Are there any differences between the two? For example, I have the following firebase service account credentials in my .env
file, which way is better?:
type="service_account"
project_id="asdfghj"
private_key_id="1234567890"
or
type=service_account
project_id=asdfghj
private_key_id=1234567890
When using .env files to store API credential, is it better to store them as strings with quotation marks or as unquoted? Are there any differences between the two? For example, I have the following firebase service account credentials in my .env
file, which way is better?:
type="service_account"
project_id="asdfghj"
private_key_id="1234567890"
or
type=service_account
project_id=asdfghj
private_key_id=1234567890
Share
Improve this question
asked Jul 4, 2020 at 15:15
ChenChen
98016 silver badges44 bronze badges
1
- Depending of how and where you are deploying your api, sometimes to have a .env file breaks the automatic devops flow because you will need to host this .env in your git repository or a human must create it in your server before the startup. How do you solve this? – JRichardsz Commented Jul 4, 2020 at 15:32
2 Answers
Reset to default 4Quotes are used monly when you have a blank space in your value
some_key="some value"
And/or special characters
some_key="some-value"
regex="^\s*-. ^"
If your are using numbers, and you want to get a numeric value, don't use quotes:
some_key=123456
It really depends on what the value of the key is. I use quotation marks only when I have a special character as the value or spaces in the value.
APP_NAME="Hello World"
APP_DESCRIPTION="This description contains spaces"
SECRET=password1234
However, if you do not have any special characters it really does not matter. It is a preference issue, and syntax. Your team may also request a certain syntax.
In Laravel we use DotEnv
They remend
If you need to define an environment variable with a value that contains spaces, you may do so by enclosing the value in double quotes.