1
00:00:00,420 --> 00:00:00,780
Nice.

2
00:00:01,200 --> 00:00:06,390
And once we have connected to the database next, I want to set up some basic routes.

3
00:00:06,840 --> 00:00:10,860
So first, I want to just set up a good route to our home page.

4
00:00:11,800 --> 00:00:19,840
When I want to invoke the Express Jason McGuire and I'll let you answer why we need that middle order.

5
00:00:20,350 --> 00:00:28,240
And I'll only tell you once I actually set up the code and also want to set up for reforming law, as

6
00:00:28,240 --> 00:00:34,140
well as the arrow handler, one at the very, very end will import express a sync errors.

7
00:00:34,150 --> 00:00:42,250
And there's also going to be the case where I'm only going to mention why we need that package once

8
00:00:42,250 --> 00:00:43,120
I actually install it.

9
00:00:43,450 --> 00:00:46,780
So I want you to think, why do we need that package?

10
00:00:46,960 --> 00:00:47,920
What was the deal?

11
00:00:48,190 --> 00:00:50,080
So let's navigate back to abrogates.

12
00:00:50,080 --> 00:00:52,630
I'll close the sidebar just so we have a little bit more realistic.

13
00:00:53,140 --> 00:00:58,870
And I want to set up my code in between a beta version port and a port.

14
00:00:59,260 --> 00:01:01,330
So let's start here with Emerald.

15
00:01:01,570 --> 00:01:08,680
So like I said, I want a get request to our home page and we want to pass in the controller.

16
00:01:09,100 --> 00:01:12,700
Here we're looking for Eric Rec and arrests.

17
00:01:13,030 --> 00:01:19,060
As far as the response is just going to be the most basic response ever where it will go it or as nuts

18
00:01:19,070 --> 00:01:25,090
and bolts bass in the string of e-commerce API.

19
00:01:25,860 --> 00:01:30,100
So once we have a verse in place, let's start out on a bigger browser window.

20
00:01:30,520 --> 00:01:34,690
So let me navigate back and I'm just going to go with local host.

21
00:01:34,690 --> 00:01:39,200
And remember, in this case, we're going for 5000 for specific reasons.

22
00:01:39,820 --> 00:01:44,680
And if you can see e-commerce API, we are moving in the right direction.

23
00:01:45,190 --> 00:01:52,900
So let me head back to read me and I'll check this one off when we want to set up express JSON middleware

24
00:01:52,900 --> 00:01:57,220
and since it is a middleware, will place it before our route.

25
00:01:57,760 --> 00:01:59,440
So let's go above to get.

26
00:02:00,500 --> 00:02:03,690
And we want to go with app and remember not to invoke middle order.

27
00:02:03,710 --> 00:02:05,870
We need to go with app dock use.

28
00:02:06,350 --> 00:02:08,460
So this is will be applied to all the roots.

29
00:02:08,900 --> 00:02:12,140
I want to go and express that, Jason.

30
00:02:12,410 --> 00:02:13,850
Now what is the reason for this bill?

31
00:02:14,090 --> 00:02:22,190
Well, we want to have access to rejection data in our body, so have multiple requests with post and

32
00:02:22,190 --> 00:02:24,530
batch where we'll be looking for those values.

33
00:02:25,100 --> 00:02:33,230
And since we want to access them, we can use the built in middleware by the name of JSON when we want

34
00:02:33,230 --> 00:02:37,310
to set up to middleware one portal for an iPhone.

35
00:02:37,730 --> 00:02:41,990
If the user is looking for a route that doesn't exist and a second one for error.

36
00:02:42,410 --> 00:02:48,290
So if there is an error since we already have the error middleware, check it out.

37
00:02:48,290 --> 00:02:49,790
It is over here.

38
00:02:50,270 --> 00:02:51,440
We want to apply it.

39
00:02:52,010 --> 00:02:57,740
And if you remember when it comes to error middleware in Express, we need to set it up as the last

40
00:02:57,740 --> 00:02:59,180
one as a quick side note.

41
00:03:00,240 --> 00:03:06,840
I've been getting peer questions from students where they're asking why this war is important.

42
00:03:07,170 --> 00:03:13,380
Why the fog of war comes before the Arrow one, and therefore I'll spend the next video covering.

43
00:03:13,830 --> 00:03:20,070
So if you're also one of those students is wondering about tomorrow, I'll talk about it very, very

44
00:03:20,070 --> 00:03:20,310
soon.

45
00:03:20,700 --> 00:03:26,100
So I just go here with not fond middleware, but I'm getting ahead of myself because I haven't import

46
00:03:26,100 --> 00:03:26,220
it.

47
00:03:26,790 --> 00:03:29,700
So we want to go here where we have the database.

48
00:03:30,280 --> 00:03:33,630
And I guess let's go below it and I'm just going to call it newer.

49
00:03:36,240 --> 00:03:42,690
And let's import both the not found one and the error handler as well, again, both of them are located

50
00:03:43,020 --> 00:03:44,250
in our middle where folder.

51
00:03:44,260 --> 00:03:48,500
So let's go here with Konst, not found middleware.

52
00:03:48,960 --> 00:03:50,520
I'm not as equal to you require.

53
00:03:51,270 --> 00:03:53,910
And let's look for our middleware folder.

54
00:03:54,330 --> 00:03:55,860
And then more specifically, we're looking for.

55
00:03:56,280 --> 00:03:57,300
Not found.

56
00:03:57,540 --> 00:03:58,860
Let's copy and paste.

57
00:03:59,520 --> 00:04:03,120
And what we want to do here is change the name.

58
00:04:03,690 --> 00:04:06,330
And this is going to be error handler.

59
00:04:07,200 --> 00:04:12,870
Or I just call it middle of where as well, just so we're a little bit more precise.

60
00:04:13,460 --> 00:04:15,720
And we're not looking for not found in this case.

61
00:04:16,320 --> 00:04:18,750
We're looking for the error handler.

62
00:04:18,990 --> 00:04:24,950
Let's say it, and I have not is not defined a crime.

63
00:04:25,470 --> 00:04:29,480
What am I missing here around the middle, where were not found?

64
00:04:29,490 --> 00:04:29,910
Are you?

65
00:04:30,210 --> 00:04:32,160
So this, of course, doesn't exist yet.

66
00:04:32,520 --> 00:04:34,260
So let's just go here with not found.

67
00:04:34,710 --> 00:04:36,150
Copy and paste.

68
00:04:36,960 --> 00:04:42,450
And then we want to set up the same thing for our handler, since our middle order needs to be the last

69
00:04:42,450 --> 00:04:45,450
one at the very, very end of this video.

70
00:04:45,900 --> 00:04:47,310
I want to also show you.

71
00:04:48,520 --> 00:04:51,970
Why we do need to use this press is errors.

72
00:04:51,980 --> 00:04:55,420
So first, let me go back and let's set it up over here.

73
00:04:55,910 --> 00:05:02,590
I just go here with choir and we're looking for a package of express async ers again.

74
00:05:03,010 --> 00:05:04,900
You can check out the package, Jason.

75
00:05:04,930 --> 00:05:06,550
You'll see that it is there.

76
00:05:06,550 --> 00:05:09,430
So package, Jason, look for Express.

77
00:05:10,090 --> 00:05:11,380
Yep, there it is.

78
00:05:11,840 --> 00:05:18,790
And if you remember correctly, we needed this package because in our controllers, we'll use try and

79
00:05:18,790 --> 00:05:21,660
catch because we'll have some asynchronous operations.

80
00:05:22,150 --> 00:05:26,860
And instead of adding this try catch for all our controllers.

81
00:05:27,400 --> 00:05:35,200
Once we use this package, it is going to be applied to all our controllers automatically, so we don't

82
00:05:35,200 --> 00:05:39,190
need to do that manual labor or set up the middleware ourselves.

83
00:05:39,790 --> 00:05:42,970
And with this in place and move on to our next step.

