Setting up root of the project
The first thing we need to do before we can actually use Mongoose in our project is install it. Over in the Terminal, I'm going to install it using npm i, which is short for npm install. The module name itself is called mongoose, and we'll be installing the most recent version, which is going to be version 5.0.6. We're going to tack on the --save flag since we will need Mongoose for both production and testing purposes:
npm i mongoose@5.0.6 --save
Once we run this command, it's going to go off and do its thing. We can move into Atom and start creating the files we're going to need to run our application.
First up, let's make a folder in the root of the project. This folder is going to be called server, and everything related to our server is going to get stored in the server folder. The first file we're going to create is going to be called server.js. This is going to be the root of our application. When you want to start up your Node app, you're going to run this file. This file will get everything ready to go.
The first thing we need to do inside of server.js is load in Mongoose. We're going to make a variable called mongoose, and we're going to acquire it from the mongoose library.
var mongoose = require('mongoose');
Now that we have the mongoose variable in place, we need to go ahead and connect to the database because we can't start writing data to the database until Mongoose knows how to connect.