dotenv API credentials string or unquoted

Viewed 1666

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
2 Answers

Quotes are used commonly 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 recommend

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.

Related