1
00:00:00,110 --> 00:00:00,500
All right.

2
00:00:00,500 --> 00:00:08,230
And up next, let's set up a basic express server and let's also implement a Node mon package.

3
00:00:08,240 --> 00:00:14,720
Now, if you're comfortable with both of these libraries, you can stop the video and set it up yourself.

4
00:00:14,840 --> 00:00:20,090
Essentially, we want to set up a server on Port 5100.

5
00:00:20,120 --> 00:00:24,710
Now, the reason why I don't go with 5000 is because lately on a mac.

6
00:00:25,470 --> 00:00:30,870
There is an error since by default, the operating system is using that port.

7
00:00:31,170 --> 00:00:35,550
Again, if that's not the case, of course, feel free to use a different port.

8
00:00:35,550 --> 00:00:38,930
But in my case, I'm going to use 5100.

9
00:00:38,940 --> 00:00:44,730
And essentially we just want to set up a basic home route which sends back Hello.

10
00:00:45,060 --> 00:00:51,420
Now, if you're not familiar with Express.js, it's the most popular package to create servers.

11
00:00:52,300 --> 00:00:53,380
In Node.

12
00:00:53,410 --> 00:01:00,160
Yes, there are new packages popping up all the time, but Express is most likely one of the oldest

13
00:01:00,160 --> 00:01:06,910
ones and it's the most reliable one since it has been around for so long.

14
00:01:06,930 --> 00:01:14,200
And when it comes to Node one, essentially this package just spins up the server automatically for

15
00:01:14,200 --> 00:01:14,470
us.

16
00:01:14,470 --> 00:01:18,370
So we don't need to do it manually like we did in the previous videos.

17
00:01:18,370 --> 00:01:23,350
Remember when we changed something we needed to start the server again?

18
00:01:23,350 --> 00:01:26,190
So the Node one is going to do that for us.

19
00:01:26,200 --> 00:01:29,350
I will showcase that in Node 18.

20
00:01:29,380 --> 00:01:36,160
There's actually a built in way how we can do that, but that is coming up and throughout the course

21
00:01:36,160 --> 00:01:43,600
I will still use the Node one as a node in I believe the last video I was removing the files and by

22
00:01:43,600 --> 00:01:45,280
mistake I removed the server.

23
00:01:45,280 --> 00:01:46,060
My bad.

24
00:01:46,060 --> 00:01:48,550
So server is the one that we keep.

25
00:01:48,550 --> 00:01:52,460
And those test ones, those are the ones we want to remove.

26
00:01:52,490 --> 00:01:56,620
Now if you want to start working with both of these packages again, npm I.

27
00:01:57,360 --> 00:01:59,820
Express and the node mode.

28
00:02:00,000 --> 00:02:04,230
And essentially we want to create a most basic server.

29
00:02:04,230 --> 00:02:07,050
So let's navigate to server.

30
00:02:07,050 --> 00:02:10,530
JS We want to import Express.

31
00:02:11,220 --> 00:02:13,150
From Express.js.

32
00:02:13,170 --> 00:02:15,200
Basically from our package.

33
00:02:15,210 --> 00:02:19,890
Now, if we're importing from node modules, basically from libraries, then of course we don't need

34
00:02:19,890 --> 00:02:20,400
to add that.

35
00:02:20,400 --> 00:02:24,090
JS It's only for our files.

36
00:02:24,090 --> 00:02:28,470
And then we go with const app and we need to invoke it here.

37
00:02:28,470 --> 00:02:31,110
So we go with Express and then we invoke it.

38
00:02:31,200 --> 00:02:38,010
And like I said, the most basic home route essentially is going to be app dot, and then we can use

39
00:02:38,010 --> 00:02:38,790
the methods.

40
00:02:38,790 --> 00:02:41,670
So if it's a post, we go with App.post.

41
00:02:41,670 --> 00:02:44,940
If it's a patch, then we go with app dot patch.

42
00:02:45,120 --> 00:02:53,550
And of course we also have App.get, which essentially is going to respond to the get request and same

43
00:02:53,550 --> 00:02:55,740
deal like we did in the client.

44
00:02:55,860 --> 00:02:59,100
Remember when we were setting up the landing page we went with Forward Slash.

45
00:02:59,100 --> 00:03:00,180
That was our home route.

46
00:03:00,210 --> 00:03:01,560
Same deal over here.

47
00:03:01,560 --> 00:03:07,770
So depending on domain, which in our case is going to be Port 5100, well that's going to be our home

48
00:03:07,770 --> 00:03:08,310
page.

49
00:03:08,310 --> 00:03:15,910
And in here, let's pass in the controller, which essentially is responsible for handling those requests.

50
00:03:16,150 --> 00:03:23,110
And controllers by default have access to to objects, req and res and effectively we just want to go

51
00:03:23,110 --> 00:03:28,450
with arrays, dot send and what do we want to send back is the hello world.

52
00:03:28,450 --> 00:03:29,620
Let's save this.

53
00:03:29,620 --> 00:03:32,200
And now let's set up App.listen.

54
00:03:32,200 --> 00:03:37,570
So we need to provide a port where our server is going to be located.

55
00:03:37,570 --> 00:03:39,370
So we're going to go with App.listen.

56
00:03:39,370 --> 00:03:40,570
That's the method.

57
00:03:40,960 --> 00:03:43,810
Like I said, in my case, I'm going to go with 5100.

58
00:03:43,930 --> 00:03:49,570
Again, we provide a callback function over here and then in the console.

59
00:03:50,260 --> 00:03:56,410
We're going to go server running and if you want, you can provide a port.

60
00:03:56,410 --> 00:04:01,240
But since eventually we will set up a variable, I'm not going to do that right now, so I'm just going

61
00:04:01,240 --> 00:04:02,740
to say dot, dot, dot.

62
00:04:02,740 --> 00:04:07,450
And again, we can go with Node and then the server again.

63
00:04:07,450 --> 00:04:12,850
But a better option is to set up a script and set up a node package.

64
00:04:12,850 --> 00:04:21,579
And as a result, every time we make some changes in the server node, one is going to restart our server.

65
00:04:21,579 --> 00:04:23,260
So let's navigate to Package.json.

66
00:04:23,260 --> 00:04:26,800
We already have set up project and I'm going to go with the dev one.

67
00:04:27,400 --> 00:04:29,680
So npm run Dev.

68
00:04:29,950 --> 00:04:32,680
And in here, let's go with node one.

69
00:04:33,010 --> 00:04:35,770
So that's the package and which file we want to watch.

70
00:04:35,800 --> 00:04:39,670
Well we'll go with server and J.

71
00:04:40,000 --> 00:04:47,680
So again, in order to spin everything up, we just want to go with NPM run dev, just like we were

72
00:04:47,680 --> 00:04:51,340
doing on a client and check it out.

73
00:04:51,370 --> 00:05:00,970
We have server running dot dot dot and if we navigate to our browser more specifically, we're looking

74
00:05:00,970 --> 00:05:03,040
for 5100.

75
00:05:03,040 --> 00:05:10,660
And remember by default browsers perform what a get request that is correct.

76
00:05:10,750 --> 00:05:11,620
And check it out.

77
00:05:11,650 --> 00:05:14,570
Now I do need to zoom in probably just so you can see.

78
00:05:14,590 --> 00:05:16,810
So that is going to be my hello world.

79
00:05:16,900 --> 00:05:23,710
And if you see the same result, we are in good shape and we can move on to the next step.

