From the course: Databases for Node.js Developers

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

Setting up Mongoose and connecting it to MongoDB

Setting up Mongoose and connecting it to MongoDB - Node.js Tutorial

From the course: Databases for Node.js Developers

Setting up Mongoose and connecting it to MongoDB

- [Instructor] Now that we have covered why we are using Mongoose and how it simplifies working with MongoDB, let's bring it into our project. For that, I have already opened the sample project we set up during the intro. First we need to install Mongoose, so we open the terminal by clicking on Terminal, New Terminal, and there, I simply type npm install mongoose. This installs Mongoose and adds it to our project. It also installs the native MongoDB driver it uses under the hood. To connect our fast for application to MongoDB, we are using a Fastify plugin. A plugin in Fastify is a reusable module that adds functionality to our application. For example, in this case, the mongoose plugin will handle connecting to MongoDB. Our project already contains a scaffold of this plugin, but let's follow the track or the trace to see how this whole plugging loading works. So I open first SRC, and there you have the server.js file. And when you look at that, you see that we are importing a lot of…

Contents