Mongoose.js is one of the most popular NPM modules to integrate a Node.js application with a MongoDB database. It provides an easy way to model our application data and comes along with different built-in features to validate, cast, and query our database, avoiding boilerplate code.
We will use our MongoDB container that we installed in the previous section. The two pieces of information that we need are the host and port where MongoDB is running. That information is shown in the Kitematic tool in the Home/IP & Ports/Access URL
section. For example, in my case, these are localhost
and 32768
:
To install Mongoose, we will use NPM. So, in your Terminal, navigate to the wc-backend
project and run the following command:
$ npm install --save mongoose
Once the installation is done, we need to get into the src
folder and create a new folder called config
. In the config
folder, now create a new file called mongoose-connection.js
:
$ cd src $ mkdir config $ touch config...