1
00:00:00,270 --> 00:00:07,050
I'm not sure if you remember, but when I initially covered middleware in Express, we set up a small

2
00:00:07,170 --> 00:00:13,350
logging middleware and when it comes to bigger projects, such middleware becomes a very, very useful.

3
00:00:13,920 --> 00:00:16,590
Now we won't set it up ourselves from the scratch.

4
00:00:17,100 --> 00:00:21,210
Instead, we'll use a very popular package by the name of Morgan.

5
00:00:21,750 --> 00:00:23,250
And first of all, set it up.

6
00:00:23,760 --> 00:00:29,010
Take it for a test drive, and then I'll show you where you can get more info.

7
00:00:29,520 --> 00:00:32,729
And in order to set it up first, we need to install.

8
00:00:33,760 --> 00:00:37,750
And in the star, it's already installed of over here, Morgan.

9
00:00:38,110 --> 00:00:44,800
So once we have the package, we want to go back to our progress and I guess I'm going to go below the

10
00:00:44,800 --> 00:00:50,050
Express, but above the database, I will say rest of the packages.

11
00:00:51,100 --> 00:00:53,620
And let's look for to Morgan one second.

12
00:00:53,980 --> 00:00:54,430
Morgan.

13
00:00:55,620 --> 00:00:57,120
Is equal to require.

14
00:00:57,750 --> 00:00:59,990
And we're looking for the package, Morgan.

15
00:01:00,480 --> 00:01:05,980
And it is set up as a middleware so we can go above the Express Jason.

16
00:01:06,540 --> 00:01:10,860
So let's set it up as about two years and then we want to go with Morgan.

17
00:01:11,640 --> 00:01:15,060
And for a basic one, we'll just go for tiny.

18
00:01:15,660 --> 00:01:20,820
So we have few options, and again, I'll show you where you can get more info on in the second.

19
00:01:21,150 --> 00:01:28,410
And we're just going to go with tiny and what you'll notice that once we go back to the local host five

20
00:01:28,410 --> 00:01:29,010
thousand.

21
00:01:29,520 --> 00:01:34,260
And if we take a look here in the console, look and say, get sorry.

22
00:01:34,260 --> 00:01:35,340
It was a get request.

23
00:01:35,760 --> 00:01:39,070
It was to the home page and it was successful.

24
00:01:39,390 --> 00:01:40,630
And how long it took.

25
00:01:40,650 --> 00:01:44,850
And again, this looks trivial right now since we have only one route.

26
00:01:45,270 --> 00:01:48,240
But trust me, as your project gets bigger.

27
00:01:48,840 --> 00:01:54,110
This is a very useful way for you to know which rock you're heading.

28
00:01:54,120 --> 00:01:58,350
Otherwise you can just keep sending the request from the postman.

29
00:01:58,950 --> 00:02:04,050
Maybe keep getting the wrong response and you can run around like a headless chicken, but this tells

30
00:02:04,050 --> 00:02:09,840
you right away, Hey, you're hearing the Stroud essentially just helps you with the bargaining process.

31
00:02:10,150 --> 00:02:14,910
So if I'm going to go back here in the browser and if I'm going to go back to my apples one.

32
00:02:15,850 --> 00:02:21,490
Now, I'll clearly see that I'm performing a get request show for its apples.

33
00:02:21,880 --> 00:02:23,740
And I said four or four.

34
00:02:24,130 --> 00:02:30,070
Now if you want to get more info, just look for Morgan Package Morgan and p.m..

35
00:02:30,610 --> 00:02:32,350
And as far as the Ducks.

36
00:02:32,740 --> 00:02:36,400
And if you want to install, you go with AMPM AI Morgan.

37
00:02:36,670 --> 00:02:42,790
As you can see, they get quite a few weekly downloads when we get the package.

38
00:02:43,180 --> 00:02:43,630
Awesome.

39
00:02:44,020 --> 00:02:49,750
And that essentially we just need to decide how much logging in we want.

40
00:02:50,080 --> 00:02:52,510
So tiny is going to be one of the smallest ones.

41
00:02:52,930 --> 00:02:55,780
And then you saw the other options as well.

42
00:02:56,260 --> 00:02:56,920
Lastly.

43
00:02:58,060 --> 00:03:05,470
We also can set it up where we only log this if we are in development, but I'll show you that I want

44
00:03:05,920 --> 00:03:11,710
once we get there, essentially once we're done with the project for now, since we're still in development,

45
00:03:11,710 --> 00:03:14,740
we're just going to be logging pretty much every request.

46
00:03:15,070 --> 00:03:19,000
Hopefully, you see why Morgan is useful and I'll see you next VIDEO.

