1
00:00:00,630 --> 00:00:08,580
I think we've got a good initial understanding of how the filesystem module works in Noad and hopefully

2
00:00:08,580 --> 00:00:13,260
I did not lose too many of you, so hopefully there are still some students left.

3
00:00:13,270 --> 00:00:19,880
And of course, because I fully understand that seeing this for the first time is probably a bit overwhelming.

4
00:00:20,370 --> 00:00:27,480
And what I would want to do next is cover the last initial module, the built in module, and that is

5
00:00:27,480 --> 00:00:34,650
going to be the module which is going to allow us to set up a Web server.

6
00:00:34,990 --> 00:00:36,990
Now, please keep in mind one thing.

7
00:00:37,020 --> 00:00:42,630
We'll just cover the basics, because the large part of this course is going to be creating your own

8
00:00:42,630 --> 00:00:45,060
server and setting up the API.

9
00:00:45,390 --> 00:00:52,740
Now, granted, we will use an abstraction on top of the module, and that is going to be the package

10
00:00:52,740 --> 00:00:54,840
by the name of Xpress.

11
00:00:55,050 --> 00:00:57,210
But the whole point is going to be exactly the same.

12
00:00:57,240 --> 00:01:03,180
That's why, again, we're not going to cover everything in greatest detail at the moment, because

13
00:01:03,180 --> 00:01:05,580
I don't see the point of repeating myself.

14
00:01:06,060 --> 00:01:13,270
And I would want to go back to abcess, zoom back in just so you can see better what is happening.

15
00:01:13,530 --> 00:01:15,960
By the way, let me check my zoom level.

16
00:01:16,320 --> 00:01:22,410
So I'm going with settings and I think that you did my zoom level is two at the moment.

17
00:01:22,650 --> 00:01:28,590
And then back in the address, let's grab the A.P. module and we'll sign it.

18
00:01:28,620 --> 00:01:30,090
Some kind of variable, as always.

19
00:01:30,580 --> 00:01:32,160
Let's go with require.

20
00:01:32,430 --> 00:01:34,560
And we're looking for HTP.

21
00:01:34,800 --> 00:01:36,030
That's the module name.

22
00:01:36,240 --> 00:01:41,540
And the method we would want to use is create the server again, will send us some kind of variable.

23
00:01:41,550 --> 00:01:43,800
And in this case, the variable name will be server.

24
00:01:44,040 --> 00:01:51,390
Then we go with HTP create server and this creates server method is looking for a callback.

25
00:01:51,720 --> 00:01:58,590
And in that callback function we have two parameters and both of those parameters are objects.

26
00:01:58,830 --> 00:02:05,100
And since there parameters, you can call it whatever you want, but a common practice is calling them

27
00:02:05,110 --> 00:02:06,360
reck and.

28
00:02:07,140 --> 00:02:11,210
Now this first parameter represents the incoming request.

29
00:02:11,460 --> 00:02:16,680
So imagine a client is requesting from the Web browser your webpage.

30
00:02:16,990 --> 00:02:24,840
So you'll have information about the method and all kinds of useful stuff in that request object.

31
00:02:24,990 --> 00:02:28,050
And the response is what we're sending back now.

32
00:02:28,200 --> 00:02:28,860
We're not done.

33
00:02:28,860 --> 00:02:30,600
Of course, we'll set up more code here.

34
00:02:30,810 --> 00:02:36,750
But before we do anything, we also would need to specifically say what port our server is going to

35
00:02:36,750 --> 00:02:37,470
be listening to.

36
00:02:37,680 --> 00:02:41,180
And that's why I will go with server and listen.

37
00:02:41,190 --> 00:02:42,630
So that's another method.

38
00:02:43,410 --> 00:02:51,030
Again, this is arbitrary, but I'm going to go with 5000 again if this looks like a lot of gibberish

39
00:02:51,030 --> 00:02:56,310
where we have the request response as well as the ports, don't worry later.

40
00:02:56,310 --> 00:03:03,450
And of course, I'll cover that in more detail as well as show you some useful slides and all that good

41
00:03:03,450 --> 00:03:03,770
stuff.

42
00:03:04,080 --> 00:03:09,030
And as far as the response, well, we have few methods we have.

43
00:03:09,030 --> 00:03:09,420
Right.

44
00:03:09,660 --> 00:03:11,030
So we go with arrest.

45
00:03:11,040 --> 00:03:12,660
And again, this is the object.

46
00:03:12,660 --> 00:03:15,120
I notice here how I'm not using the rec yet.

47
00:03:15,450 --> 00:03:16,890
So I'm not checking for anything.

48
00:03:17,100 --> 00:03:19,020
I'm just concerned about my response.

49
00:03:19,290 --> 00:03:22,950
And the method name is right and the right.

50
00:03:23,190 --> 00:03:30,510
We just come up with some kind of text and I'll say welcome to our home page.

51
00:03:31,740 --> 00:03:38,370
Page, and once we have sent back the response, I also add one and my request, so I'm going to go

52
00:03:38,370 --> 00:03:43,790
with her as DOT and and once we're done setting up the code instead of the callback function.

53
00:03:44,160 --> 00:03:50,310
Now, of course, I would want to open up my terminal, clear everything, and we would need to spend

54
00:03:50,310 --> 00:03:50,960
the sucker up.

55
00:03:51,270 --> 00:03:56,970
And of course, the way we do that is node and then abcess, since that is to finally make sure that

56
00:03:56,970 --> 00:03:57,400
you save it.

57
00:03:57,430 --> 00:03:59,190
Do so before I run.

58
00:03:59,490 --> 00:04:02,410
I'll save it and then notice something interesting.

59
00:04:02,820 --> 00:04:04,650
Notice how we're not exiting.

60
00:04:04,960 --> 00:04:11,520
So previously, every time we around the file, every time we around node and then whatever to find

61
00:04:11,520 --> 00:04:13,380
them, we exited from the file.

62
00:04:13,380 --> 00:04:13,620
Right.

63
00:04:13,920 --> 00:04:17,880
So Node was done executing the code and we just moved on.

64
00:04:18,209 --> 00:04:21,019
Now in this case, since we have a web server.

65
00:04:21,529 --> 00:04:25,860
What the Web servers do, they keep on listening for requests.

66
00:04:26,100 --> 00:04:29,330
And actually you want your server to always be up.

67
00:04:29,700 --> 00:04:38,820
And of course, if I go to my Web browser and I'm like this bigger and if we go with localhost and of

68
00:04:38,820 --> 00:04:45,320
course in this case we have five thousand Verity's, we have welcome to our homepage.

69
00:04:45,750 --> 00:04:50,160
So now of course we have effectively created our first website.

70
00:04:50,460 --> 00:04:55,950
Now granted it's very basic but at least we have something on screen.

