Using the variables
It's time to actually remove that data from the codebase and use it through environment variables.
Now, let's go back to the DatabaseModule
and connect to the database in a different manner: asynchronously and using a factory. This means that, instead of already receiving the credentials directly in the code, it will await the environment variables to load in order to use them. Now we can also use just the URL, and have the following result:
Also, back in the file docker-compose.yml, let's use the password
from the .env too.
And do the same with the port
.
In the data-source file, unfortunately we'll need to use the packages dotenv and dotenv-expand directly, as it has no integration with Nest and, because of that, the ConfigModule
can't be used here. We'll also need to write the imports manually because these packages are sub-dependencies, and as such will not benefit from code completion.
Commit - Using environment variables
Last updated