Come back everybody Johnny B you with soap's dot com in this lesson we are going to set up a local hosting
environment.
Now like I already said.
Once you have it all set up and you're chatting in your app it's going to be like you're in a room all
by yourself just talking to yourself.
But knowing how to set up local instances is extremely important since you should never do code changes
on Live servers.
You want to always develop and test things out locally first.
OK.
That being said if you already got the API code hosted using one of the two prior methods in the previous
video this lesson is completely optional.
You do not have to have it locally hosted for the rest of the course.
We will touch on it a couple more times and do a few things but you don't have to have it.
I do recommend that you stick around though because we're going to do some cool stuff and it's a great
skill to know.
All right.
Moving on.
So since the API is built on Node Yes and Mongo D-B we are going to need to download these libraries.
Like I said earlier this isn't a course on API dev.
So I'm going to show you how to use the tools but we may not go into too much of the details or I'm
going to pull up a browser here and we are going to just Google.
I was going to google no yes but it took me right to it.
No just dot org and all we need to do is download and you want the LDS version this is the recommended
for most users.
Althea stands for long term support.
So when I click on that and that's just going to download a package and once that's done I'm just going
to open that up and go through the install process music.
Do you agree.
Install putting in your admin password
and clubs and you can go ahead with that store to the trash easy.
Next up we need to get Mongul D-B.
So I'm going to open up a new tab and Google mongered D-B
and come down here too among Would you be for giant ideas.
And we want to go to download and we have here instructions for installing with homebrew.
So we're going to go ahead and do that with homebrew.
OK so we're going to use homebrew.
So let's see here we can it's going to come down here install among would be community edition with
homebrew.
So you can click here to go to homebrewed and to install it and you can't copy this you are l copy and
go to open up a terminal and paste it and have it installed but it'll just update it.
And if you press Return to continue on pop or font size here and put in my password and that'll install
I'll take a few minutes.
All right so that's installed.
And let's go back to our instructions.
So it says to do a brew update brew update
already up to date.
As I just installed it and then we just been to say Brue install mongered D-B to install fungo DBI
and since I already had it installed then it just tells me that.
All right so that's how you'll go about installing no japes and Mongo D-B.
So those are the two main tools that we are or libraries that we're going to need.
And so the node handles the energy is used for handling the API code and the mongrel D-B is used for
the databases database stuff.
OK.
All right so now that we got those two done we're going to download a couple of tools that will help
us in working with the API code.
And the first one is called post man just Google that and then find out here supercharge your API workflow.
So you can download the postman and just click on Mac OS and it'll start downloading for you.
So that's downloading.
I already have it installed.
So I'm just going can actually cancel that download.
But once you have it download go ahead and open it up OK so the postman does.
It's a really cool app that lets you do web requests using all of the important methods like get Post
put all that kind of stuff and you can have headers and you can have a body.
And so we're going to be using this a little bit in the local hosting environment to make sure things
are working right.
So that's a really great tool and I have a collection so these are called collections different types
of requests.
So I'm actually going to show you how to import the one that I have for you guys.
I'm going to delete my collection and then inside of your assets folder.
Let's see here do this.
OK so instead of your assets folder you have a file called MacT chat API collection.
So in postman and postman go to import here and then you can either drag that file in or choose files
because when we say desktop assets and the one we want is right here MAXjet API collection.
OK there we go.
And that just reinforce those those requests that I had.
And so what we can do is here for instance this one here says register user it's a post request it has
already the local host information you Earl and the body and the header.
And so once we have the local instance up and running all I have to do is press send and it will actually
register a new user.
And then you can off in that user you can add a user.
You can you can do pretty much anything that the API is capable of doing right here from postman.
You can run a request to find all the users of that user.
So it's a really great tool for working in local environments or even even a live API is pretty much
anything that you need to do web requests for.
And it's really helpful because you can you can do all of that right here and you can see the results.
You don't have to set up all of the client side information.
You don't have to code an Alamo file request to get the response parse the saw and all that kind of
stuff.
You can get it all right here in Postman.
All right so the next program tool that we're going to use is one called robo Mongo you can get that
up portable Mangu dot org and just download that app OK.
And I have that also on my computer already.
So when you open it up you'll get this right here robo remotely connections.
And I just named mine for the 27 0 1 7 is the one that you that you want and you can edit it and change
the name of it.
But make sure but make sure that it's local host and 27 0 1 7.
OK.
Save that and say connect but if you don't have Mangu up and running then nothing will happen so quick
that if you and I just hang on for the next step here.
All right so I'm going to go ahead and quit this browser window.
So we have our four tools that we did for this lesson.
No mom would be the postman.
And robo Mongo.
So we got this superhero team of apps and now we need them to all work together to actually do something
good.
So what we're going to do is I'm going to open up a terminal again and I'm going to clean my terminal
command key I'm going to CD to the desktop CD into our Mac chat API and then I'm going to say have time
to open.
Adam for this project I'm going to bring that over here.
And so in the previous lessons we set up the poor and Mangu you are l.
And that's for using the hosted the web hosted servers but for local hosting I'm just going to comment
those two lines out and we already have it set up here.
So I'm going to uncomment these two lines.
So now we are going to be listening on our local port of three thousand five and our Mangu you are l
is our local host 2 7 0 1 7 chat API.
Okay.
So when to save that and then come back into terminal and to get NPM or to get the API code running
with node when you're inside when you're seeded into the achcha API you want to say NPM install and
that's going to install the no packages that are required for for this API to function and I already
did that so that's why it's saying a predatory field then you're going to do.
N.P. am well first we need to get Mangu running.
So do you can have multiple tabs open interm also if you say command t that will open up another commit
another terminal tab.
And so here we're going to just say Mongo D.
And this gets the Mangu Daymond up and running.
And you can see here that it says waiting for connections on port 2 7 0 1 7.
So among the D-B is up and running.
So now I'm back in our chat API directory.
We can now say NPM run Dev and that will fire up the API code on Node.
Right there we go sevices started on port three thousand five just as we expect the Mongul D-B you are
all you see right here is the same as what we have in our in our API code and database connection is
ready.
So this is really cool stuff guys.
We got our locally hosted API code running working with mongrel D.B and it's just waiting for us to
do some work.
So when the open postman backup and puts you over here on the left we're going to open up robo Mongo
and you say connect.
And this time it should connect and then we have a database for a chat API.
It's going to put you over here on the right.
And now here in Bozeman I actually maybe I don't want this quite like that.
OK.
So with our and our Mac chat API collection I'm going to use a registered user and this is all set up
already so local host V-1 account register.
And so this is the API function to register a user.
So looks like we have a few steps here first right here says one.
We're going to register user 2.
We are going to log in the user and three we are going to add create a user.
OK.
So the first step is to register the user and let's see here.
Let me open up robo Mongo chat API.
Let me see if we already have any collections.
OK so we don't have we don't have any collections here so I'm going to just say press send.
You can change the email on password if you want to verify that it's working for you.
No say send and.
OK it looks like the user exists with the given name already so I'm going to go ahead and just change
this to Doc is press and again OK so it looks like our API code crashed so to stop the API code you
can say control C and that will stop the process.
Same thing with Mongo D.
And so we're just going to fire that back up and say NPM around dev
K and we're back up and running.
I'm going to jump back into postman and I change the e-mail and I'm going to say send.
And here we go.
We see that we successfully created a new account.
And so what is actually happening here.
Let's take a quick detour and always said it wasn't going to jump too much into API code but we can
we can take a couple of minutes here.
All right so we are sending a request to this you are Al V-1 account register.
All right so let's open up Adam your project viewer is not showing you can use command shift backslash
to get that to show.
OK so I wanted to show you some of the files in here.
So if we go to a controller account here you see the one account register.
This is the API code that is called When we run this post man post.
So we are passing two parameters the email and the password and it creates a new account and then sends
back a status saying successfully created a new account.
And so that's the message that we're seeing here.
And so feel free to browse through the through the API code kind of familiarize yourself with it a little
bit.
Yes.
So then the next thing that I wanted to show you what was once we do this with postman we're actually
writing to our local Mangu database so if we open up robo Mongo and we we refresh our chat API and we
click on collections and then click on accounts you'll see that we have the the account that we just
created username G.
G dot biz.
All right so that is pretty cool.
Next up we can off a log in user and so we click on off logging user the body J.J dot com and we send
that here we should actually get a more information return.
We're going to get the user name as well as a token.
OK so most of the API requests are locked down which means that no one can access that information unless
they are logged in and they have this off token.
All right so I'm going to copy this off token and then we can add a user using that token that we're
going to go to had a user body or headers.
And I'm going to replace that token with this valid one that we just generated.
OK.
And then in the body we can change this up name to say Johnny B.
Email is J.A.G. dot com avatar name is dark 5 and the Avatar color is hexa value.
These these two things will make more sense here in a couple of lessons.
When we were back in Aix code but I can do this and say send.
And there we go we have a we've created a new user and it returns this information for us.
And if we go back into robot Mangu and we refresh here.
So if we right click on chat and say refresh then we see that we have a new collection here called users
click on that.
We have the information that we just sent from postman.
So this is some really cool stuff guys.
I hope you're excited about this.
I think this is super super interesting and cool stuff.
I mean just the options that are open to you as a developer once you know how to create and use back
and a.p eyes is huge you know.
So I hope your guys are enjoying this.
And I think this is about all we're going to cover right now in this lesson with local hosting.
Just to recap we downloaded noti Yes mum would we be a couple of helper programs using postman and robo
mango.
We we were running the local instance of the API code using node.
And to do that you in terminal you'll say NPM install then PM run dev.
But first you have to have mung would you be up and running with Mongo D.
And yes that's pretty much it.
And the next lesson is learning be jumping back into X code and actually implementing the client side
code to communicate with our API is all right.
So Kobe is enjoying this and I'll see you in the next one.