So let's now work on getting
that database hosting up and running.
For this I searched for Mongo DB Atlas,
since this will be the managed service we'll be using for
the reasons mentioned before.
And the great thing about Mongo DB Atlas is that you can get
started for free.
Here if you go to the pricing page to the cloud offering,
you can get started for free with this shared plan here.
And hence, we can simply click on, try for free here.
Though, as always, if you are serious about your website
and also your database therefore, the free plan,
of course has certain restrictions
you might not be too happy with in the long term.
And therefore you might want to consider upgrading to one of
the paid options,
if you have more traffic and more requests.
But to get started, the free plan is great.
You don't even need a credit card as you see here.
And therefore now
we can enter our email address to create a new account here.
Now, here I'll quickly fill in my details
and then click create account.
And this will now create us such a free Mongo DB Atlas
account.
And once that finished as a next step,
you'll have to verify your account.
So that's the next thing you should do.
And there after, you can sign in
with that account you created.
Now, initially you should end up
on a starting screen that looks something like this.
And here you can now click on, build a database.
Now, here, we want to go with that, right
most option, the basic option,
because that's available for free.
And then here's stick to basic.
Now we can choose the underlying cloud provider,
which will be used by Mongo DB Atlas.
And we can stick to AWS for this.
As a side note, you could also directly use AWS.
They offer tons of services related to hosting and other
services that run on remote machines.
But here we'll use Mongo DB Atlas,
which uses AWS implicitly.
And I'll keep all these default settings here.
Under a cluster here we want to use the free forever option,
the M0 sandbox, which should be the default.
We use that database version.
We can keep the default cluster name or give it a different
name.
As a side note, a cluster is in the end
the thing that will run your databases later.
And therefore, then we can click on create cluster
so that this cluster with the databases is created.
And as it says here,
this can take a couple of minutes until it's done.
Now, we don't have to sit here and wait for it though.
We can already go to the security area because there,
we got two things that we need to tweak.
First with the database access.
Here we want to add a new database user
because that will be the user
with whom we then connect to this database.
So this controls,
the permissions are node JS application will have when it
connects to this database, through this user.
And for this I'll choose password as the authentication
method, and then add a new user.
Which all named Maximilian or default or whatever you want.
And add a password and I'll choose a fairly insecure one
here.
You of course should probably auto-generate one and then
copy that. But here I'll use my own one for this demo.
And then here very important for the database user
privilege.
We want to choose read and write to any database.
That is what our users should be able to do.
Then we can click add user here.
And next we can move on to network access.
Here on the network access page,
we can control which other servers and machines will be
able to connect to our database.
And here under IP access list,
we want to click on add IP address.
And now we could add our current IP address,
if we would want to use Mongo DB Atlas from our local
machine.
If we would run the node express website on our local
machine and that locally running websites should connect to
Mongo DB Atlas.
But of course that won't do the trick if our website
is running on Heroku's machines,
Because dos machines will have different IP addresses.
Therefore for that,
we could either enter the IP address off the server
our website will run on.
If we knew that IP address in advance,
but with the basic Heroku deployment option,
we don't know that in advance because Heroku will assign IP
addresses dynamically.
And therefore I'll choose allow access from
anywhere, which means everyone will be able
to connect to our database.
Though that sounds a bit more insecure than it is
because you will also need the user credentials,
which we set up a couple of minutes ago.
So just with that access granted alone,
it's not the case that everyone will be able to connect.
The user credentials also the matter.
So here I'll set up this.
Everyone is allowed to send connection requests setting.
And with that, we can now wait
until our database is done starting up.
So once this cluster is done and once this network access is
done, configuring,
and then we'll be able to continue with deploying our
website.
So here that cluster did now start successfully.
And now we can click on connect here to learn how we can
connect to it.
Now there are various options,
but we want to connect our application.
So our website, so we can click on this.
And indeed we are using Node.js.
So we can leave that default.
And the latest version of that Mongo DB driver,
which is that Mongo D package, which we're using.
And they after then here we get the URL,
which we can use to connect to our database.
It has this user, which I created automatically filled in.
So that will be part of that URL.
And we have this password placeholder,
which we will have to populate with the user password
ourselves.
Now that's the URL,
which we would now want to use instead of this URL,
but keep in mind,
we're using environment variables for this.
So I will keep this URL here for local development
and we'll provide the production URL.
So this URL here, through an environment variable after we
deployed our website to Heroku.
And therefore I'll keep this window open here,
but I'll continue with the deployment steps now.
Since now we can continue with pushing our code
to Heroku and starting our website there.