Chapter 10. Deploying Our API
Imagine if each time a user wanted to access our API to create, read, update, or delete a note we had to go meet them, laptop in tow. Currently, this is how our API works, as it is running only on our individual computer. We can resolve this by deploying our application to a web server.
In this chapter we’ll take two steps:
First, we’ll set up a remote database that our API can access.
Second, we’ll deploy our API code to a server and connect it to the database.
Once we’ve followed these steps, we can access our API from any web-connected computer, including the web, desktop, and mobile interfaces that we will develop.
Hosting Our Database
For the first step we’ll use a hosted database solution. For our Mongo database, we’ll be using MongoDB Atlas. This is a fully managed cloud offering backed by the organization behind Mongo itself. Additionally, they offer a free tier that will work well for our initial deployment. Let’s walk through the steps of deploying to MongoDB Atlas.
First, visit mongodb.com/cloud/atlas and create an account. Once you’ve created an account, you’ll be prompted to create a database. From this screen you can manage the settings of your sandbox database, but I recommend sticking with the defaults for now. These are:
Amazon’s AWS as the database host, though Google’s Cloud Platform and Microsoft’s Azure are also offered as options
The closest region with a “free tier” option
Cluster Tier with a default value of “M0 ...