From the course: Advanced Express

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Adding MongoDB and Mongoose to an Express project

Adding MongoDB and Mongoose to an Express project

From the course: Advanced Express

Start my 1-month free trial

Adding MongoDB and Mongoose to an Express project

- [Instructor] With all the credentials in place, we will now make MongoDB available to Express. For that, we will use Mongoose. Mongoose is an object data modeling laboratory for MongoDB. It's very commonly used, lets us create schemas and makes working with Mongoose from NodeJS generally easier. On the flip side it comes with some performance overhead. So if your applications are heavy on database reads and writes and you run into performance issues, Mongoose might be an optimization target. Let's install Mongoose now, for that, I type, npm install --save and my project wrote. And I want to isolate everything that has to do with the database connection in a model on its own. For that I create a new folder in server called, lib. And in lib I create the new file, db.js and here on line one I will, add const mongoose = require('mongoose') And further down I add, module.exports and I want to export a function connect and this function is asynchronous, and takes a database connection…

Contents