Environment variables
Variables that are isolated from the codebase.
We'll begin with our database credentials. First, create at the root of the project the file .env, which will hold our environment variables. Here, we can safely store the credentials.
This file will never be published to the code repository, as the file .gitignore includes it. You may notice that the file name in the file explorer is grayed out.
Even though we have all those credentials, we can use just the URL to connect to the database, which can be created from them. For this reason, once again in .env, let's create the URL.
As we have just created the .env file, we can already create the .env.example file too. It is a reflection of the .env but with sample data, so that other developers may know the structure they must have in their own .env file. As our .env file has data for development testing, we can just copy its contents over to .env.example. Other developers may then copy this to their .env and adjust as necessary.
However, before we can begin using these variables, some issues need to be resolved, and that will be done in the next section.
Last updated