1
00:00:02,070 --> 00:00:08,700
Doing all of this data parsing and response generation code on our own is quite cumbersome and hard

2
00:00:08,730 --> 00:00:09,830
to scale,

3
00:00:09,840 --> 00:00:11,930
this already is quite unreadable here

4
00:00:12,000 --> 00:00:16,290
and of course we could optimized this in certain ways but it's certainly not how you would want to build

5
00:00:16,320 --> 00:00:22,180
bigger applications. Now similar issues exist on client side Javascript though, there

6
00:00:22,180 --> 00:00:28,650
also if you have very complex apps with a lot of access to your documents, where you create elements

7
00:00:28,650 --> 00:00:32,160
and insert elements, this can get cumbersome. Therefore there

8
00:00:32,160 --> 00:00:37,650
we also learned about React.js or other frameworks that help us with that and we also learned that

9
00:00:37,650 --> 00:00:41,550
there are in general libraries that can make certain tasks easier,

10
00:00:41,550 --> 00:00:43,740
the same exists for Node.js.

11
00:00:43,770 --> 00:00:49,470
You can google for Express.js to find one of the most popular Node.js libraries you can use,

12
00:00:49,470 --> 00:00:55,500
you can visit its page, expressjs.com to learn more about it and in the end this is just a framework

13
00:00:55,590 --> 00:01:01,860
for Node.js which makes building web applications, web servers with Node.js easier.

14
00:01:02,040 --> 00:01:08,250
We install it with npm and in order to do that, we first of all need to turn this into an npm project here,

15
00:01:08,880 --> 00:01:14,640
so we can do that by running npm init here, npm is available since we installed Node.js and you

16
00:01:14,640 --> 00:01:17,730
can just confirm all the defaults here.

17
00:01:17,730 --> 00:01:22,770
Once you did that, you have a package.json file and now you can install new dependencies in this

18
00:01:22,770 --> 00:01:23,400
project,

19
00:01:23,400 --> 00:01:28,980
it's the same approach and idea as we had it on the client side when we managed our project there and

20
00:01:28,980 --> 00:01:31,190
enriched it by npm packages.

21
00:01:31,200 --> 00:01:38,880
The only difference is that now we will not need webpack or any other tool to use that because Node.js

22
00:01:39,030 --> 00:01:44,820
natively support these packages in Node modules which is also why the folder is called Node modules as

23
00:01:44,820 --> 00:01:49,470
you will see and we don't need webpack or anything like that to combine all these files.

24
00:01:49,470 --> 00:01:51,930
That's one difference, we need it on the client side,

25
00:01:51,930 --> 00:01:58,830
we don't need it on the server side. So let's now install Express.js with npm install express 

26
00:01:58,830 --> 00:02:04,350
--save which will install it as a production dependency and you see this new dependency entry

27
00:02:04,350 --> 00:02:07,670
here in package.json and you see the node modules folder

28
00:02:07,770 --> 00:02:14,880
and as I said, Node.js is natively capable of working with node modules, you don't need any extra tools

29
00:02:15,120 --> 00:02:23,380
to combine all these different files. With that, I will rename the file here to pure Node.js and add

30
00:02:23,380 --> 00:02:29,590
a new empty app.js file where we now can get started with Express.js and learn how we set up a

31
00:02:29,590 --> 00:02:36,160
web server with that and how that makes it much easier to work with incoming data and also to send back

32
00:02:36,220 --> 00:02:44,350
responses, how to outsource our HTML code into separate files and not have it inline here and

33
00:02:44,380 --> 00:02:46,450
how we can then build web applications with that.
