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.
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