- [Narrator] How do we provide the previously created
credentials to our application?
We need a way to work with different databases
depending on the environment.
Luckily, our configuration does already support that
so if we look into server config index js,
we see here on line six that we have a property development.
On line 17 we have a property production
and if we scroll down, on line 28,
we have a property test.
On the other hand, we should not store credentials
with our application code,
especially if this is committed
to some version control system like ki-tar.
That's why I installed a module called dotenv already,
to see that I'm requiring it up here on line one,
and what dotenv does is it looks for fouls
with the name dotenv in our project route
and brings the setting in then
as environment variables on process
and you can see that here, for example,
on line 14, we bring in process.env.DEVELOPMENT_DB_DSN.
So set these variables to sample project or ID
contains a file dotenv sample,
and I will now go ahead and rename it to dotenv,
and in there you already see the prepared properties
that we want to bring in to the setup,
the database collection.
So I will now head over to my temp file
from before, I cut out the credentials from there,
and I paste them into dotenv.
Let's remove the right sidebar here
and I will now copy them up to the right
configuration properties, so I will copy production
and will paste it to the production DSN.
I will copy test and copy it up here
and the same also, of course, for development.
We can now also remove this temp file we had before
and let's real quick also look into our gitignore file.
This file contains patterns for all files
that should not be committed to version control,
so I look into that and in line 58,
you will find .env, this dotenv file will never end up,
for instance, on ki-tar.
Now we are ready to use the newly configured
mon-ga-de-plast in our application
and the project contains a test function that makes sure
that all databases are reachable.
You find it in test, DB, connect.
Just to run this test, I will now add
into the integral terminal official studio code,
and run npx mocha test/db/connect and as we see,
all tests are passing, which means
that we can connect to mongodb at-list properly.
Again, if your IP address tends to change frequently,
please make sure that you have white listed
your current IP address if the connect suddenly fails.