Hey there, everyone that they share.
And in this video, we're going to be injecting a whole lot of configuration because obviously we need
body parts to handle the Jasons.
We need to handle the files as well.
We need to handle the cookies as well, Morgan as well.
And I will also be injecting the swagger documentation.
I won't be writing it throughout because it will extract and consume like a really lot of extra videos.
We will also deviate from a path already we have gone through quite in depth of that, but still I'll
inject it.
Maybe you want to write it onto your some free time.
You can go ahead and do that.
We'll configure the project according to that.
So first let's see what all we have installed.
We have even got the Morgan up here to just go ahead and scroll at the very end of it.
This is where they give you a majority of the functionality this needs to go into J So we're going to
be calling, Hey, Morgan, let's go ahead and inject this one up here.
So inside, yes, we can close the rest of the other guys.
We don't need it.
So at the top of it, once the express is all done, we're going to be requiring this.
MORGAN Hit a couple of lines of enter.
Now, the important thing about the Morgan is it needs to come before you are creating any of the roots
up here.
So notice here, there we go, we create ABCD, get before that we need to use this Morgan and all of
that.
Feel free to use this one or maybe have a tiny they have a lot of configuration.
It's up to you to read it.
Read it up here.
We are going to go ahead and inject it up here.
So there we go about use.
It's a kind of a middleware.
So there we go.
And let me go ahead and write a comment here.
This is simply a morgan middleware.
Save that as soon as you do this.
Now, you have to just stop the server once and you need to start it one more time.
Again, these are the Morgan configuration.
They actually work like this, so go ahead and kind of restart that.
Now, what is going to happen after that?
If you go up here back onto any of the local root, you go ahead and hit reload on here.
Now you have made a request up here.
Now notice here we have got some of the crash because probably there is something missing up here.
So it says, hey, it took an ID request and all of that.
So we we won't be using this ID and method and a whole lot of things.
We will be going with the classic method of tiny.
So this is a default package I guess, and it should be working right out of the box, otherwise we'll
see it.
Let's reload that and there we go.
So this is what happens when you give it a tiny in case you didn't noticed, I'll show you one more
time.
So let me expand this a little bit and.
Kind of a clean this up.
So how can I clean this?
No, I cannot.
Let me stop this and clean this now and run this again.
So there we go.
This is up and running now.
And if I go ahead and hit a reload on any of the route, what Morgan does is just gives you this, that
there was a get request on this route, which is slash API, slash V1, slash dummy and the time and
how much time it does took.
Now, again, this totally depends on how you want to configure the Morgan.
I usually go with the tiny one, but they give you Morgan like dev roles and common and there is no
shortage of all of them.
So again, this only logs four x and five x of the responses, not the others in case this is dev.
It is really configurable.
That's all I wanted to show to you.
Okay.
So we have got now Morgan being configured.
Now we can monitor all the requests that are coming back and forth and it's a little bit easier to handle
the situation.
Now, this Morgan is all done so we can go ahead and add our regular middleware verse.
So we're going to call this one as regular middle viewers.
So what are these regular middle wears?
These are the some which we need to bring it up here, but some are just here in the app.
So we're going to say dot use.
And in case you know that we have already discussed that that express need to handle the JSON as well.
So there we go.
It handles the JSON as well.
Maybe it might want to handle some of the things which are coming up into the body itself.
So we need to have this express as well.
So we're going to say express dot URL and coded and we have already discussed that.
Why we need to provide one more option which is extended equals true.
Okay.
So these are the most basic one.
But we also know that we need to handle cookies as well as images.
So let's go ahead and require that part.
So we're going to go ahead and say and in fact, for the Morgan as well, for the consistency sake,
I'm going to go ahead and put const.
KONST There we go.
So the first thing we're going to need is let's go ahead and grab a cookie parser.
So cookie parser.
And that's going to be coming up from require cookie parser.
We will be needing some of the file upload as well.
So let's bring that file up, express file upload as well.
So we're going to say file upload that will be coming from require express file upload.
There we go.
And again, the classic way of using them up is let me go ahead and add another comment for you.
So this is going to be for cookies and file middleware.
There we go.
Now, obviously, if somebody might be checking out your code, he will just get impressed that everything
is nicely commented out and is being mentioned pretty nicely.
So let's go ahead and say that this is going to simply say use.
I want to use.
Come on to use.
I want to use the cookie parser just like that and I want to upload the file as well.
So I'm going to say use this one is going to be file upload.
Okay.
So hopefully all of these basic configurations are done at least as of now, for now.
But we also want to go ahead and inject some of the some of the previous work as well, like the documentation
work.
So for this, I'll upload one of the previous code that we wrote in the earlier section.
So this is all we need.
We need to install a YAML Jess and we need a swagger yaml again.
This is the thing that we have already done and there is no harm in bringing something from your own
written code.
So again, don't panic out.
And well, this is absolutely okay.
So we just need basically three of these lines.
So we need to have swagger, document, file, upload.
We have already done through that and this line as well.
So we're going to go ahead and copy this and we'll bring it up here as well.
So let's go ahead and add this one up here and let's add a comment for swagger documentation.
There we go.
And one thing here is that file upload is already being done.
So we are not worried about this part.
And this part is in with this guy.
So there we go.
Now, obviously, this is not going to work because there is a little bit of more configuration required.
But first thing is YAML and swagger express UI need to be installed.
So let's go ahead and clean this up and say NPM install first is Yamal JS and the second one is swagger
dash UI, Dash Express.
And again, in case you are wondering what this is, the section two was all about it.
We had so much of in-depth in depth talk about this one, so please don't panic out on that.
Let's go ahead and create a file onto this here.
I'll create a file up here.
Which is swagger dot yaml.
Now obviously this file is not going to be recorded automatically, so we need to create a node manga's,
not just JSON.
So we're going to go ahead and say node on DOT JSON.
So it gives us all the node configuration.
Again, we can bring the configuration and save us some time directly from here.
So not on JSON, it just basically is an extension list.
So let's go ahead and have that.
What are the existing extensions that we have?
First, let's see that.
Obviously this is saying, hey, problem are there.
Yeah, I'll give you the file and path and everything.
Don't you worry.
Okay.
Looks like it's not giving us as of now.
But let's go ahead and have this one.
So extensions are all done and ready and in the app dogs, let's save this one.
So now we have YAML and all of these things coming up nicely and we have app use a middleware for this
one and we have a loading of Swagger Docs as well.
So hopefully this should be all okay.
And where is my swagger docs?
There we go.
So A.T.M. should be all okay.
Let's go ahead and try to run it one more time to see let's see that.
How many of the bugs we need to fix them up?
Okay, so this looks everything is all good now.
And we are also monitoring JSP, Gsx and YAML.
In case we need to add any other extension.
We'll just come back and add this one.
Let's bring up a little bit more of the documentation here.
So Swagger, YAML and let's also bring up all of this one here.
So tell the server's components and this much we are going to be bringing up into the swagger YAML.
Let's quickly configure this one.
This is not to learn a swagger express and all of that.
This is a full fledged t shirt store API.
The discussion is AE a course.
A course to create create a API.
For E com store.
Come on.
There we go.
Subversion and all of these are fine.
Definitely.
This is not the proper email.
I would like to come up with the different email.
Probably my own email.
Okay.
So this is all good.
Servers are all looking fine and we are having a local host slash API slash.
This time we are going with the v one.
So yeah, v two is not available.
This is working right out of the box components.
We are having the cookie and the beer are wrath.
So that is nice.
Let's go back and see if we can bring a little bit more to see if something makes sense up here, at
least giving you some of the basic start.
OC So at this time these are the path.
So we are having just the path of let's just say we want to go for dummy and this is a string tag is
going to be simple home page or just home is fine and summary returns agreed from AE 200 response.
This is all good.
It requests gives you a string and all of that.
So hopefully this should be good and now we should be able to see something onto this route.
So let's go ahead and say that this time we we need to go need to check where we need to go.
We need to go onto slash API, slash docs.
So slash API dash docs and I forgot a slash there.
There we go.
So now even our stored API is an authentication and everything is up here.
So in case you are interested in that, you can actually go ahead and keep on writing this documentation
as well whenever you get time and you can keep a documentation being maintained for this one as well.
Again, as I told you, I won't be maintaining this documentation too much.
I would be focused rather on creating the functionality, working through our app and all of that.
But as of now, the configuration is all done.
Now we need to work on a little bit of the extra things like connecting with the database, connecting
with some of the errors, show you some of the customized error handling and a little bit of that.
So let's go ahead and catch up in the next video.