13. Module introduction

In module number 2, we're going to take the first steps in building our backend API.


We're going to begin by setting up Express, which is a micro framework that is perfect for creating APIs.

We'll be scaffolding the API using the MVC structure.

You'll see here in our server folder that we now have files for controllers, models, and a routes file, too.


To help us develop this API before we've built a client app to consume it, we'll be using the Postman API development environment. We'll install that and also setup some test requests.

For example, you can see here I've got a POST /items request with a JSON body. And when I send that to our server, it's returning a 200 request and we're seeing a response object.


Speaking of which, since our API will need to persist the data it receives, we'll be using MongoDB, which is a non-relational database and is great for loosely structured data like that of PrintBay.

In fact, we'll be using Mongoose ORM which is an abstraction of Mongo DB that makes CRUD operations a breeze.

You can see here one of the validated data models that we'll be creating in a later video.

We'll then use our model to save data we receive via the API using async/await syntax in order to create our first functioning API endpoint.

Committing code

Before we begin coding this module, we'll need to check out the module 2 starter branch in the git repo.

Assuming you've just finished module 1 and you've got some uncommitted file changes, it's probably a good idea to first commit those.

Or, if you aren't too sentimental about it, you can just discard your changes by going:

$ git reset --hard HEAD

Checking out code

Once you've dealt with the file changes, you can now checkout the module 2 starter code by going:

$ git checkout module_02_start

Don't forget to do a NPM install after that, and also, double check that you've got your server environment file still.

If you don't have it, there's instructions in the README file for creating a new one.