Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,140 --> 00:00:05,590
‫So let's see that big picture or at least parts of it
2
00:00:05,590 --> 00:00:11,460
‫because MongoDB requires this extra database server setup which we'll tackle in a separate module
3
00:00:11,620 --> 00:00:18,700
‫but let's see this part at least, the React and Node Express API communication part in action in a simple
4
00:00:18,700 --> 00:00:19,540
‫application
5
00:00:19,600 --> 00:00:25,420
‫and no worries, this is just a short demo application, we'll build one, a way bigger one in the course project
6
00:00:25,510 --> 00:00:32,150
‫from the ground up throughout the rest of this course. Attached, you find a zip folder which can unzip and in
7
00:00:32,150 --> 00:00:35,340
‫there, you'll find a frontend and a backend folder.
8
00:00:35,560 --> 00:00:41,170
‫Now combined, this makes up your MERN application and this is a very simple dummy application which
9
00:00:41,170 --> 00:00:43,030
‫I prepared for you.
10
00:00:43,030 --> 00:00:48,860
‫The frontend holds React application, the frontend folder here was created
11
00:00:48,960 --> 00:00:54,880
‫or this project here was created with create-react-app which is a tool by the React team to create React
12
00:00:54,880 --> 00:00:55,940
‫projects
13
00:00:56,200 --> 00:01:02,500
‫and it holds a React application with some components because React is all about components as you will
14
00:01:02,560 --> 00:01:06,130
‫also learn again in the React refresher in a separate module,
15
00:01:06,130 --> 00:01:11,320
‫for now you can just take it for granted, so we'll have the different components, the building blocks of
16
00:01:11,320 --> 00:01:18,280
‫our frontend user interface so to say and with the backend folder, with exactly one core file, server.js.
17
00:01:18,280 --> 00:01:27,970
‫Now to run these ends here, you need to install Node.js. You can install it from nodejs.org
18
00:01:28,030 --> 00:01:34,330
‫and there, simply download the latest version, 13 in my case but that of course will change over
19
00:01:34,330 --> 00:01:40,720
‫time, does not really affect the way Node works or looks like however and simply download that latest
20
00:01:40,720 --> 00:01:46,630
‫word and walk through the installer you get there, the default settings are fine and this will install
21
00:01:46,630 --> 00:01:54,910
‫Node.js, so this special Javascript runtime onto your machine. It will also install one other tool onto your
22
00:01:54,910 --> 00:01:59,560
‫machine and that's npm, the Node package manager.
23
00:01:59,560 --> 00:02:05,920
‫This is a tool which is required anyway to install the various dependencies, so third-party libraries
24
00:02:05,920 --> 00:02:11,680
‫we use in both our backend code as well as our frontend code because even though the frontend code
25
00:02:11,680 --> 00:02:18,940
‫is not run by Node.js, it still will use third-party libraries which are then simply used by the browser
26
00:02:19,090 --> 00:02:22,980
‫or also an important part, by our build setup,
27
00:02:22,990 --> 00:02:29,440
‫our development setup where we have a dummy server that serves our frontend which reloads the page
28
00:02:29,470 --> 00:02:33,910
‫whenever we change something, which optimizes our code and so on.
29
00:02:33,910 --> 00:02:39,130
‫These are all steps which are not run once we deploy our finished frontend but which help us during
30
00:02:39,130 --> 00:02:44,800
‫development and for that, we also need third-party libraries and actually also the Node runtime which
31
00:02:44,800 --> 00:02:47,670
‫runs this entire frontend build process,
32
00:02:47,770 --> 00:02:51,790
‫so we definitely need Node.js to do anything here.
33
00:02:52,120 --> 00:02:59,570
‫Now you also see I opened this project here in an IDE, in an integrated development environment.
34
00:02:59,620 --> 00:03:04,450
‫This is Visual Studio Code, a great free to use IDE
35
00:03:04,480 --> 00:03:09,760
‫you can find if you google for VSCode and which you can then install from the page you get to,
36
00:03:10,000 --> 00:03:12,160
‫code.visualstudio.com.
37
00:03:12,160 --> 00:03:17,980
‫It's free and available for all operating systems, so simply download it and walk through the installer
38
00:03:18,100 --> 00:03:19,770
‫if you want to use that same IDE
39
00:03:19,780 --> 00:03:24,100
‫here as I do. Now in that IDE here,
40
00:03:24,130 --> 00:03:27,310
‫I also installed some so-called extensions,
41
00:03:27,430 --> 00:03:33,310
‫you can get to the extensions menu with view extensions and there specifically, the extensions
42
00:03:33,340 --> 00:03:40,780
‫I recommend that you install are the material icon theme to make sure your file icons look like mine
43
00:03:40,780 --> 00:03:49,410
‫if you like that look, path intellisense which can help you with auto completion of file names, prettier
44
00:03:49,590 --> 00:03:51,980
‫which helps you with autoformatting your code
45
00:03:52,140 --> 00:03:58,000
‫so that it is easy to read and you don't have to format it manually and with all that installed,
46
00:03:58,020 --> 00:04:01,950
‫also if you go back to the Explorer or use the shortcut you see here,
47
00:04:02,010 --> 00:04:09,870
‫I also recommend that you look into the themes you got configured, under code, preferences, colour theme,
48
00:04:10,260 --> 00:04:12,920
‫there you can switch it to a different theme,
49
00:04:12,940 --> 00:04:17,290
‫I'm using the dark plus default dark theme here which gives me the look you see here.
50
00:04:17,520 --> 00:04:21,470
‫You also here see the file icons I got from the material icon theme.
51
00:04:21,600 --> 00:04:22,620
‫Last but not least,
52
00:04:22,770 --> 00:04:26,580
‫I already talked about prettier and that auto formatting,
53
00:04:26,580 --> 00:04:32,310
‫you can always check out your keyboard shortcuts and there specifically the format document shortcut
54
00:04:32,340 --> 00:04:38,490
‫is one you should bind because that will help you use that prettier extension to automatically reformat
55
00:04:38,490 --> 00:04:42,900
‫your code but with that, that's basically the setup I have here.
56
00:04:42,900 --> 00:04:49,050
‫Then I opened that extracted folder which holds the backend and frontend folder and I'm now ready
57
00:04:49,050 --> 00:04:58,230
‫to go, well or almost. First of all, as I mentioned, every end has some packages, some dependencies
58
00:04:58,260 --> 00:05:05,100
‫it uses, you'll find those in the package.json file which is your project management file you
59
00:05:05,100 --> 00:05:12,300
‫could say and you'll see that I treat backend and frontend as separate projects because they are logically
60
00:05:12,300 --> 00:05:13,650
‫separated.
61
00:05:13,650 --> 00:05:20,010
‫Now you see here for the backend in the package.json file, I got three dependencies, three third
62
00:05:20,010 --> 00:05:21,070
‫party libraries
63
00:05:21,090 --> 00:05:26,070
‫this project uses. For the frontend, for the React application,
64
00:05:26,130 --> 00:05:34,200
‫I got these three dependencies - React, the library we use, React DOM which is also part of React and React
65
00:05:34,200 --> 00:05:39,930
‫scripts which in the end helps us with our build setup and with this dummy server that serves the React
66
00:05:39,930 --> 00:05:42,220
‫application and so on.
67
00:05:42,480 --> 00:05:48,750
‫Now to install these dependencies, you need to open up your terminal or command prompt and you can use
68
00:05:48,750 --> 00:05:50,540
‫the one integrated into your IDE,
69
00:05:50,610 --> 00:05:56,910
‫you can go to terminal, new terminal here to open it and then navigate into your frontend folder and
70
00:05:56,910 --> 00:05:59,050
‫in there, run npm install
71
00:05:59,130 --> 00:06:05,190
‫and this uses the npm tool which was installed together with Node.js to install all the dependencies
72
00:06:05,490 --> 00:06:08,340
‫which are mentioned in the package.json file.
73
00:06:08,460 --> 00:06:15,240
‫It will then create such a node modules folder where these dependencies and their dependencies are actually
74
00:06:15,240 --> 00:06:16,300
‫stored in.
75
00:06:16,710 --> 00:06:19,320
‫Now doing this just for the frontend alone is not enough,
76
00:06:19,500 --> 00:06:26,280
‫so I will open a second terminal and also navigate into the backend folder because there, I also want
77
00:06:26,280 --> 00:06:31,780
‫to install all the dependencies, so that for both the frontend and the backend, we got that installed.
78
00:06:31,860 --> 00:06:35,800
‫So let's wait for this installation process to finish and thereafter,
79
00:06:35,820 --> 00:06:41,100
‫let's start our two servers and see how they communicate with each other.
80
00:06:41,400 --> 00:06:46,680
‫So the installation of all the dependencies in both the frontend and backend folder finished and now let's
81
00:06:46,680 --> 00:06:50,040
‫simply see what we got there before we have a look at the code.
82
00:06:50,040 --> 00:06:55,800
‫Now keep in mind, we have two logically separated ends here and here during development at least, we will
83
00:06:55,890 --> 00:06:58,320
‫also have two separated servers.
84
00:06:58,320 --> 00:07:06,120
‫Now of course both runs on our machine here, on our computer but actually we will run these two different
85
00:07:06,240 --> 00:07:09,720
‫ends under two different domains.
86
00:07:09,720 --> 00:07:12,120
‫Now let's see what we got here, in the frontend folder,
87
00:07:12,120 --> 00:07:19,450
‫you can run npm start to start a development server that's part of the setup basically added by this React
88
00:07:19,450 --> 00:07:24,490
‫scripts dependency which will host your React application, this React
89
00:07:24,520 --> 00:07:26,090
‫single page application.
90
00:07:26,200 --> 00:07:31,390
‫So it's a development server which in the end hosts this single index.html file which you find in the
91
00:07:31,390 --> 00:07:37,570
‫public folder there which then in turn will import all the scripts it needs and launch your React app.
92
00:07:38,460 --> 00:07:43,760
‫You find that application, it should open up automatically actually, under localhost:3000.
93
00:07:43,760 --> 00:07:48,410
‫Localhost might look strange but this is your domain,
94
00:07:48,420 --> 00:07:54,120
‫it's available on your local machine, it's a special domain there and :3000 is the port on
95
00:07:54,120 --> 00:07:56,520
‫which we're visiting this and combined,
96
00:07:56,520 --> 00:08:02,930
‫this actually is a domain as it would be the case for
97
00:08:02,940 --> 00:08:03,560
‫yourpage.com,
98
00:08:03,570 --> 00:08:06,890
‫so this combined is the actual domain
99
00:08:07,080 --> 00:08:14,190
‫and if you would visit another page on let's say localhost:5000, that might look very similar but
100
00:08:14,190 --> 00:08:19,760
‫it would actually be a totally different domain as if it were served by a totally different machine.
101
00:08:20,490 --> 00:08:26,760
‫So here React automatically runs on localhost:3000 and that's our React single page application.
102
00:08:26,760 --> 00:08:32,020
‫Now let's go to the backend folder and there, you can also run npm start.
103
00:08:32,190 --> 00:08:38,160
‫Now here, nothing opens up automatically but you will see that you're now in a process which doesn't
104
00:08:38,160 --> 00:08:40,770
‫stop, so you can't enter a new command,
105
00:08:40,770 --> 00:08:42,790
‫by the way it's the same for the frontend.
106
00:08:42,900 --> 00:08:49,110
‫That is the default and that is what should be the case because that means you have a running server.
107
00:08:49,110 --> 00:08:56,280
‫You can always stop these processes by hitting control c on your keyboard but then of course the server
108
00:08:56,280 --> 00:08:57,050
‫will be down,
109
00:08:57,060 --> 00:09:02,910
‫so as long as you're developing, you should have it up and running. So we get these two running servers
110
00:09:03,180 --> 00:09:09,590
‫and the Node backend server here actually will run under localhost:5000,
111
00:09:09,600 --> 00:09:16,260
‫however if you enter that you will not see anything because this specific endpoint, / is
112
00:09:16,260 --> 00:09:17,430
‫not supported.
113
00:09:17,430 --> 00:09:23,160
‫Remember when I said that you as a developer decide which endpoints you want to support and you want
114
00:09:23,160 --> 00:09:24,630
‫to execute code on,
115
00:09:24,630 --> 00:09:31,480
‫well that's not one of them. Things change if you enter /products there however, you see now you
116
00:09:31,480 --> 00:09:34,340
‫get back in the end a Javascript object,
117
00:09:34,360 --> 00:09:41,440
‫this is actually this JSON notation I was talking, about which holds a product's key and then an empty
118
00:09:41,440 --> 00:09:42,400
‫array.
119
00:09:42,400 --> 00:09:48,610
‫So here we seem to get back some data, even though it's empty and that already looks quite promising
120
00:09:48,790 --> 00:09:54,760
‫and now really keep in mind, localhost:5000 is a totally different server than
121
00:09:54,930 --> 00:09:56,840
‫localhost:3000.
122
00:09:56,940 --> 00:10:03,210
‫Now obviously here we have some communication problems, with your Node server up and running however,
123
00:10:03,690 --> 00:10:09,600
‫reload the React app on localhost:3000 and you will see that the loading part goes away and
124
00:10:09,600 --> 00:10:12,710
‫instead we see could not find any products.
125
00:10:12,750 --> 00:10:19,710
‫Now let's add a book here for let's say 12.99 and click add product and what you see is
126
00:10:19,710 --> 00:10:21,700
‫it now appears down there.
127
00:10:21,750 --> 00:10:28,620
‫Now that's nice but what you will also see if you reload now and you keep both servers up and running in
128
00:10:28,620 --> 00:10:36,340
‫between, you still get that, you see loading for a fraction of a second and then you see a book here.
129
00:10:36,510 --> 00:10:44,500
‫So it looks like the book we created here really was stored somewhere, was stored on our backend server
130
00:10:44,760 --> 00:10:49,470
‫and when we reload the React app, we're fetching data from that server
131
00:10:49,470 --> 00:10:52,080
‫and since the server runs on its own domain
132
00:10:52,080 --> 00:10:58,050
‫but technically of course on the same machine as our frontend, that request is super fast which
133
00:10:58,050 --> 00:11:04,380
‫is why we see that loading text only for the fraction of a second if we see it at all.
134
00:11:04,590 --> 00:11:10,590
‫But the really important thing here is that we are storing data on our backend, so on the Node Express
135
00:11:10,590 --> 00:11:15,020
‫app or with help of the Node Express app and we're fetching it from there.
136
00:11:15,120 --> 00:11:16,770
‫Now that's how it works,
137
00:11:16,830 --> 00:11:22,760
‫let's now have a look at the code to get a rough understanding of what's working together there.
15829
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.