Environment variables allow us to define some configuration that is decoupled from the code-base. It makes the application deployment easier in different environments (e.g. Heroku). Information that varies (hence the term variables) depending on the environment should be included in this file. Also, sensitive information like API tokens or database URLs should not be in this source code or known by unauthorized entities.
Node.js provides a global variable called process.env
which is an object that contains all environment variables accessible to the developer. These environment variables are stored in a file called .env
and, by convention, they are defined in a capitalized snake case, e.g DB_URL
.
If you check the repository, you will find a file called, .env.example
that contains variables used by the backend application.
First, fork the repository and clone it on your machine (if you face some issues during this step, you can refer back to the GitHub Guide).
To allow the backend to connect to your database, create a .env
file that is an exact copy of .env.example
and modify it as follows:
Note that changes in the .env
are ignored by git and that is why we provide the .env.example
file to serve as a skeleton or a specification for the variables. As a matter of fact the .env
file should not be pushed.