1
00:00:00,660 --> 00:00:09,150
In one of the earlier sections on fundamentals we created an edge TTP So were using Express.

2
00:00:09,520 --> 00:00:16,800
We're going to use the same approach here and create an HDTV server.

3
00:00:17,050 --> 00:00:24,430
And since we have already seen how to create and as GTP said we're before just to speed up the process.

4
00:00:24,430 --> 00:00:30,120
I'm simply going to paste in some code that I have ready with me.

5
00:00:30,160 --> 00:00:32,610
All right let's walk through this code.

6
00:00:32,620 --> 00:00:36,610
We are referencing a couple of NPM audience here.

7
00:00:37,410 --> 00:00:41,160
EX-PRES is to create an STV server.

8
00:00:41,370 --> 00:00:46,550
Compression is to enable compression and this is optional.

9
00:00:47,010 --> 00:00:50,900
That is just to work with the directory path.

10
00:00:51,980 --> 00:01:02,240
Body passer as we have seen earlier will allow us to parse the SCDP regressed in the GSM format.

11
00:01:03,320 --> 00:01:09,400
And cars is to control the cross region resource sharing.

12
00:01:10,250 --> 00:01:23,160
We also reference the App Store S-5 which will hold our rest API endpoints are the routes then we call

13
00:01:23,160 --> 00:01:34,380
the Express function and then enable cars and compression we are using the day for cars configuration

14
00:01:34,530 --> 00:01:36,810
and in a production environment.

15
00:01:37,170 --> 00:01:40,430
You should provide more control cars.

16
00:01:40,450 --> 00:01:44,810
All is with outdoor set muse.

17
00:01:44,910 --> 00:01:55,920
We tell express the location of our SOS edged team efforts then we use the body parser middleware to

18
00:01:55,920 --> 00:02:05,550
parse all incoming requests to Chaisson and then we tell express the directory from where to serve the

19
00:02:05,820 --> 00:02:09,900
static pages of our app to the end users.

20
00:02:11,360 --> 00:02:17,720
And we also tell express the location of our routes.

21
00:02:17,760 --> 00:02:21,950
Finally we have some code to catch errors.

22
00:02:22,140 --> 00:02:26,560
So for 3:56 our page not found errors.

23
00:02:26,670 --> 00:02:32,600
This curve is simply going to render the index page.

24
00:02:32,610 --> 00:02:41,140
This is because no application that we are building is going to work only as a arrest API.

25
00:02:41,550 --> 00:02:49,580
So any SCDP requests to our arrest API will be handled by our app out fine.

26
00:02:49,710 --> 00:03:01,530
And so all other as GDP requests likes in the actual front end to the end user etc will be handled by

27
00:03:01,620 --> 00:03:03,030
our angular

28
00:03:05,570 --> 00:03:06,170
said.

29
00:03:06,300 --> 00:03:16,150
Express is simply going to render the index page far or not API grasps the next page is the starting

30
00:03:16,150 --> 00:03:21,500
point of our Front-End angular.

31
00:03:21,670 --> 00:03:31,230
Then in case of any server side errors we simply launch them to the console and also return the error

32
00:03:31,260 --> 00:03:35,200
message as SCDP response.

33
00:03:35,220 --> 00:03:43,180
Finally we export our app more ado so our server just fine can use it

34
00:03:47,100 --> 00:03:49,020
in the server just fine.

35
00:03:49,020 --> 00:03:56,430
I'm going to paste in the code that I have ready with me and then we'll work through it.

36
00:03:56,460 --> 00:04:04,440
We referenced the TTP and debug models and then reference are at Modu as well.

37
00:04:06,270 --> 00:04:11,900
We then sent the board to be asked to serve our application.

38
00:04:12,000 --> 00:04:20,090
We look it up from the environment variables and if we don't find a value there which is the default

39
00:04:20,120 --> 00:04:37,000
mode as 3000 then we create the server with SCDP God create server and pass our app reference.

40
00:04:37,050 --> 00:04:46,260
And finally we ask the server to listen to incoming requests on the predefined or rest of the code it's

41
00:04:46,320 --> 00:04:53,840
optional and useful for debugging purpose.

42
00:04:53,890 --> 00:05:02,870
Then we have to create the API endpoints or routes that people from different operations on our dynamically

43
00:05:02,890 --> 00:05:08,090
table on behalf of our application to do that.

44
00:05:08,110 --> 00:05:10,930
Open the app Roadstar just fine

45
00:05:13,720 --> 00:05:24,820
Briest we must reference the Express Madill and then declare Routier variable are constant as expressed

46
00:05:24,880 --> 00:05:25,990
dot router

47
00:05:28,660 --> 00:05:37,750
and then we can define our API functions using different methods available with this express router

48
00:05:38,080 --> 00:05:41,670
line get hosed and so on.

49
00:05:41,800 --> 00:05:52,630
We'll do that shortly in the next lecture we also have to export this routers are apt or just find can

50
00:05:52,630 --> 00:05:57,450
use it just like that.

51
00:05:57,480 --> 00:05:58,420
All right.

52
00:05:58,620 --> 00:06:05,000
Before we can test we must install the NPM all use that we use here.

53
00:06:05,190 --> 00:06:21,350
So NPM install dash dash save followed by names of all the modules we need that is EX-PRES edge vs compression

54
00:06:22,760 --> 00:06:25,220
bad body parser

55
00:06:28,970 --> 00:06:29,870
Carlos

56
00:06:33,050 --> 00:06:36,940
as GDP and debug

57
00:06:42,760 --> 00:06:45,130
Osten.

58
00:06:45,140 --> 00:06:49,370
Now let's ram MP and start to spin out the server.

59
00:06:51,000 --> 00:06:56,750
And we can see that server is now listening on port three thousand.

60
00:06:57,630 --> 00:07:07,190
Let's open localhost goaland 3000 in our browser and we should see our index page with Hello World message

61
00:07:09,360 --> 00:07:10,080
awesome.

62
00:07:10,080 --> 00:07:18,280
Our server is ready and now we can create different routes for our rest API.

63
00:07:18,540 --> 00:07:21,570
So let's do that in the very next lecture.
