Now that we've created our ToDo list up and we've learned all about how we can persist data using databases
and more specifically using MongoDB a NoSQL database, then the next step is learning how we
can actually deploy these apps which have a database associated with it out there onto the worldwide
web.
Currently, in order to access our website we go to localhost:3000 and that means that we're using our
local computer as the server to serve up the information and data in our website. And that backed
of course relies on Node.js. Now in the last module
we also learned how to persist our data to save it to a database using MongoDB.
Now the MongoDB database is also served up from our local computer and the URLs that we use to access be it
our server or MongoDB all have the word localhost in it.
So if you take a look up here, when
we've been accessing app we've been using the hypertext transfer protocol. We've been going to a port
3000 on the localhost and we needed to access our database, we've been accessing it at port 2701
7
also on our localhost. Now the part before the colon differ because here we're using the hypertext transfer
protocol,
so a set of rules that govern how we transfer data across the Internet to access web pages.
But here we're using the MongoDB rules which determines how you can access data in a MongoDB database.
But essentially everything is all hosted on the same laptop that we're using for development.
And this is great for testing while you're developing your apps but currently nobody other than ourselves
can actually access our website which kind of defeats the purpose of it being a website
right?
If it's just made for us.
So what can we do?
Well we know from previous lessons that we can use a data server that's online 24/7 and attached to
the Internet backbone which will be able to host our Node.js server and be able to deliver our web
site wherever it's requested across the Internet.
And we've been using Heroku to do this which means that instead of using localhost:3000 we can use
some sort of app name .herokuapp.com and anybody no matter where they live or how they're accessing
the internet they can all access this web page through this address on the World Wide Web.
Now that's all very well and good for an app that doesn't have a database, but our app does. In our
case our todo list app actually needs to talk to the database to be able to create, read, update and
delete data from our database.
And if it's trying to do that from Heroku servers to the Mongo database that's hosted locally on our
computer then that's not really going to work.
So there's a few differences between a server and a workstation.
For example the server pretty much has to be online 24/7 so that anybody who requests data from it can
access it no matter what hour of the day. Also depending on what ISP or Internet service provider you're
going with they have strict rules regarding whether you can set up a server using your home Internet
plan.
So what we have currently is a workstation and we need to move our database to a server for it to be
served up 24/7 and across the internet.
What we need to do is we need to set up another server which is capable of hosting MongoDB databases.
And the service that we're going to use is MongoDB's own cloud service which is called Atlas. And
this is going to allow us to have a web based address. MongoDB Atlas is going to host our database
and serve up the data whenever it's needed.
So that means that our Node.js app on Heroku will be able to make the necessary requests to our database
that's hosted on the MongoDB Atlas cloud service and we'll be able to delete or update and be able
to get data back from that database and that will all happen behind the scenes. Any users who needs to
access your website will be going through your app.herokuapp.com
and then your backed will liaise with MongoDB Atlas in order to talk to the database.
So we no longer have any need for hosting our server or our database locally
and that frees up our app and liberates it and puts it onto the Internet so that anybody can access
it.