1
00:00:00,210 --> 00:00:05,820
And lastly, I would just want to reiterate the point that even though you might not write your own

2
00:00:05,820 --> 00:00:09,630
event, events are a core building block of note.

3
00:00:10,020 --> 00:00:17,010
And effectively, as you're building and writing out the code for your node and application, you are

4
00:00:17,010 --> 00:00:23,640
using those events at the end of the day anyway, because a lot of built in modules rely on them.

5
00:00:24,420 --> 00:00:31,140
As a quick side note, if you'd like to see the code that we wrote in previous to lectures, you can

6
00:00:31,140 --> 00:00:38,360
just navigate to 13 event a matter and not assure that our quickly set up a server.

7
00:00:38,850 --> 00:00:44,610
And again, the code for this one you can find at 14 and then request event.

8
00:00:44,850 --> 00:00:52,470
So copy all the contents from the file and just copy and paste and notice something interesting.

9
00:00:52,710 --> 00:00:59,510
Again, yes, we're getting the module and remember the setup that we have used so far where we go with

10
00:00:59,520 --> 00:01:06,780
HTP create server and then we pass in this callback function and then of course the callback function

11
00:01:06,780 --> 00:01:11,310
will be invoked every time someone visits our server.

12
00:01:11,460 --> 00:01:15,350
So every time the request comes in.

13
00:01:15,810 --> 00:01:20,520
Now there's another way how we can set it up by using event API.

14
00:01:20,820 --> 00:01:27,000
So we still create a server, we go with HTP and then create server function.

15
00:01:27,150 --> 00:01:35,030
But instead of passing in the callback function like we did previously, server has the method on does

16
00:01:35,040 --> 00:01:35,760
that ring a bell?

17
00:01:36,120 --> 00:01:37,590
Remember our previous example?

18
00:01:38,100 --> 00:01:43,200
We had our own instance and it had the method of on.

19
00:01:43,200 --> 00:01:43,640
Correct.

20
00:01:43,860 --> 00:01:45,240
So the same goes for server.

21
00:01:45,570 --> 00:01:51,180
So server has the method on and we listen for request event.

22
00:01:51,480 --> 00:01:58,300
And when that request comes in, then of course again we have the callback function that handles it.

23
00:01:58,650 --> 00:02:05,340
So behind the scenes server omits the request event and then of course we can listen for it.

24
00:02:05,520 --> 00:02:06,750
We can subscribe to it.

25
00:02:06,780 --> 00:02:10,470
Listen for it or respond to it however you want to call it.

26
00:02:10,500 --> 00:02:13,080
And the way we do that, we go with server on.

27
00:02:13,290 --> 00:02:20,210
And then this is a specific name because, of course, it omits that specific name behind the scenes.

28
00:02:20,210 --> 00:02:24,070
So make sure that it is a request and then the same spiel.

29
00:02:24,540 --> 00:02:25,650
Now, how do I know that?

30
00:02:25,650 --> 00:02:32,520
Well, if we go to no documentation and if we look for HTP, we keep on scrolling, keep on scrolling,

31
00:02:32,760 --> 00:02:38,570
eventually we'll hit the server and or here I can see that it is a class.

32
00:02:38,970 --> 00:02:40,140
OK, that's a good start.

33
00:02:40,440 --> 00:02:42,060
And what do you see here?

34
00:02:42,510 --> 00:02:45,360
Well, I see the event right.

35
00:02:45,360 --> 00:02:48,630
And what is the event while the name is a request.

36
00:02:48,900 --> 00:02:56,970
So that's how I know that on my server, the instance that I create has the ability to listen for request

37
00:02:56,970 --> 00:02:57,360
events.

38
00:02:57,660 --> 00:03:01,200
And if you want to dig deeper, you can just click on a server.

39
00:03:01,410 --> 00:03:08,270
You notice that it extends the net server and if we keep on digging, check it out.

40
00:03:08,280 --> 00:03:10,200
So this one extends what?

41
00:03:10,590 --> 00:03:13,320
It extends the event amateur.

42
00:03:13,590 --> 00:03:20,640
So hopefully that makes it clear that even though you might not be setting up events on your own, a

43
00:03:20,640 --> 00:03:26,640
bunch of built in modules rely heavily on this concept of events.

