- Now that we have the basic server dependencies
for a project, we need to install Mongo
so we add the database when we build a server.
But also we'll use Mongo to simplify
some of the initial boilerplate.
So first, go to MongoDB.com.
Then you also have mongoosejs.com.
Mongoose basically is a library to help us
with modeling our database
and bring several built-in tools to help us with validation,
business logic hooks, etc.
If you'd like to get more details
around these two libraries,
feel free to take a look at the documentation in depth.
We'll cover some of the basics as we build our API.
So let's go ahead and install both.
So the first thing you need
when you want to install MongoDB on a Mac,
you need Homebrew.
So if you don't have Homebrew,
just copy and paste this command
inside of a terminal like so.
So, I'm going to copy this,
go inside a terminal, and paste this command.
We hit return, and this is going to install...
And this is going to install Homebrew.
But I already have it in my system
so I'm going to go ahead
and go to the instructions for MongoDB.
So for Windows folks,
all you have to do is go to try free,
click on server,
and then select the version of Windows,
and the package download, and install with this package.
What it's going to do is going to install MongoDB
as a service inside of Windows.
So once you restart Windows,
it's going to start MongoDB automatically.
For Mac people, let's go ahead and click on learn,
documentation,
MongoDB Server,
installation,
and then make sure you select the community edition,
and then install on MacOS.
So like I said, you need to have Homebrew installed first,
so if you don't have that, go ahead and install it.
Once you have Homebrew,
what you need to do is copy this first command here,
so let's go ahead and do that, copy,
and let's go to our terminal,
and then paste this command so brew tap mongodb/brew.
And while it's doing this,
we're going to go and copy the second command we'll need.
So you have to scroll down just a little bit
and then install MongoDB with this command.
So we'll copy this command again,
go back to our terminal.
Once this is done,
we paste the command brew install mongodb community.
And then Homebrew will install MongoDB for you.
So while it's installing MongoDB,
let's go back to the instructions,
and the way to run MongoDB is to run it from here,
or you can use Homebrew to start MongoDB
by doing brew services start mongodb,
or you can run it from here,
so what we're going to do is copy this command,
and go back here,
and now it's installed.
And then we paste the command,
and then it's going to start your MongoDB database server.
So, if this command is not successful to you,
what you could use as well is
the brew service start Mongo community command as well.
So both of these commands will do the exact same thing
depending on how fast you want it to run,
depending on your system,
you can use one or the other.
So, this is running your server.
If you want to connect to a Mongo shell
and actually use commands inside of the MongoDB server,
you need to start a Mongo shell which you do with this.
We're not going to use a Mongo shell in this course
because we're building an API that will connect to MongoDB
and will use mongoose to connect to MongoDB,
and then use postman to test our API.
So, just a note for you,
if you want to do MongoDB commands,
you can use a shell and start it with this command.
While MongoDB is getting started,
let's go back to Visual Studio code right here.
So the next step is to install MongoDB
and Mongoose inside of our project.
So let's go ahead and do that.
So what we're going to do is npm i or install
and we don't need to do dash dash save
unless you have a legacy version of node and npm.
And then mongoose.
And now we have those two libraries installed
inside of our system.
Okay, so now that we've got Mongoose
and MongoDB ready to go, let's move on.