Part 3: Adding MongoDB to our API.

We will continue from where we left off in  this tutorial series by adding MongoDB to our API. If you are just starting now feel free to clone all the code from the previous tutorial  here.

First we need to download the  MongoDB community server. Make sure to pick the right download for your operating system and then follow the instructions to install and get it running on your system on your system. MongoDB community server is completely free for anyone to use!

Now back to the project. In your /src folder create a file named connect.ts. It’s here we will write the configuration for express to connect to the database. In order to connect to the database we will need to use an **Object-data modeling (ODM) **tool. Using an ODM will allow provide some structure and built in business logic which will make our lives a lot easier, less writing more doing! Probably the most popular ODM for MongoDB is Mongoose so let’s install it and because we are using typescript, its types.

$ npm i mongoose
$ npm i -D @types/mongoose

#nodejs #programming #mongodb #typescript #web-development

API server setup with Express.js, Typescript, and MongoDB (Part 3)
1.45 GEEK