1
00:00:02,390 --> 00:00:05,190
Let's first of all understand npm a bit better,

2
00:00:05,530 --> 00:00:10,580
it's node's package manager as you learned and in the end it's a cli, a command line interface.

3
00:00:10,630 --> 00:00:17,830
We always used it from the command line from the terminal by running npm and then some command, mostly

4
00:00:17,950 --> 00:00:24,640
npm install in this course. The idea behind packages or tools like npm

5
00:00:24,700 --> 00:00:30,520
and every programming language has a similar concept you could say is that we might have some isolated

6
00:00:30,520 --> 00:00:38,810
functionality, some code that we wrote or that we came up with that does something useful,

7
00:00:38,830 --> 00:00:41,130
let's say it generates a random number.

8
00:00:41,140 --> 00:00:47,090
Now we can use that in our web application but maybe we want to use it in other applications as well

9
00:00:47,140 --> 00:00:54,280
because this isolated functionality does not depend on our business logic in the project we're creating

10
00:00:54,370 --> 00:00:56,900
or maybe we want to share it with the public.

11
00:00:57,310 --> 00:01:03,910
Well if we want to share it internally or externally, we can put it into a package with the help of npm.

12
00:01:04,000 --> 00:01:11,650
You can use npm not just to install packages but also to create and share packages through that npm

13
00:01:11,650 --> 00:01:17,680
repository which is a cloud service where you don't have to pay for where you can host packages you

14
00:01:17,680 --> 00:01:23,740
created and this is also a service where you will in the end fetch packages from with the npm install

15
00:01:23,740 --> 00:01:24,500
command.

16
00:01:24,760 --> 00:01:30,970
So in this repository which is managed globally, you'll find thousands of packages obviously and if

17
00:01:30,970 --> 00:01:38,680
you now have some node project, you can use any of that, you can use any of those packages with the npm

18
00:01:38,680 --> 00:01:41,000
install command through that cli

19
00:01:41,110 --> 00:01:44,550
and that is how you add packages to your project,

20
00:01:44,650 --> 00:01:51,760
no matter if that is a package shared by you and you can also have private repositories or private packages

21
00:01:51,850 --> 00:01:52,390
on npm

22
00:01:52,390 --> 00:01:58,360
by the way, that is something you do have to pay for but you can always use public packages and share

23
00:01:58,420 --> 00:01:59,990
packages with the public.

24
00:02:00,140 --> 00:02:02,030
That's the idea behind npm,

25
00:02:02,050 --> 00:02:07,840
now let's have a closer look at the official npm repository page and the available commands

26
00:02:07,840 --> 00:02:11,870
we can use. You can visit npmjs.com,

27
00:02:11,870 --> 00:02:14,170
that is the official page of npm

28
00:02:14,210 --> 00:02:16,210
and there you can search for packages,

29
00:02:16,220 --> 00:02:21,500
for example we could search for express here which is of course a package we used, the express framework

30
00:02:22,010 --> 00:02:28,160
and then you see all kinds of packages that kind of were found for that, maybe packages that use express,

31
00:02:28,420 --> 00:02:29,090
maybe also

32
00:02:29,120 --> 00:02:31,420
of course the express package itself.

33
00:02:31,760 --> 00:02:37,990
And if you click on that, you find some quick docs, you see the versions that were released here

34
00:02:38,060 --> 00:02:40,850
so here you can see the different versions

35
00:02:40,940 --> 00:02:44,950
you could install through npm, you can target a specific version

36
00:02:44,950 --> 00:02:52,630
by the way by going to your terminal and there with npm install, you can choose the package and then an @

37
00:02:52,760 --> 00:02:55,660
sign and then a specific version number,

38
00:02:55,670 --> 00:03:01,550
for example we could choose 4.16.3 by typing for 4.16.3

39
00:03:01,550 --> 00:03:06,890
and now we would install that version into our project. If we select no version, the latest one is picked

40
00:03:06,890 --> 00:03:07,940
by default,

41
00:03:07,970 --> 00:03:11,580
that's just a little side note. So we can see that version history,

42
00:03:11,690 --> 00:03:14,910
we can see which other packages this package relies on

43
00:03:14,980 --> 00:03:19,040
and these packages will be installed for you automatically when you install expressjs

44
00:03:19,070 --> 00:03:19,620
.

45
00:03:19,670 --> 00:03:25,610
So these will also end up in node modules as will the dependencies of these packages and that is why you

46
00:03:25,610 --> 00:03:31,280
quickly end up with a big node modules folder by the way because you have a lot of dependencies of dependencies

47
00:03:31,280 --> 00:03:32,590
of dependencies.

48
00:03:33,050 --> 00:03:35,530
You also see other things like the official home page,

49
00:03:35,530 --> 00:03:41,630
the github repository, so the repository where you can find the source code for this package and so

50
00:03:41,630 --> 00:03:42,410
on.

51
00:03:42,410 --> 00:03:44,170
So this is really useful,

52
00:03:44,230 --> 00:03:49,760
now if you want to learn more about the npm command though, so what else you can run besides install

53
00:03:49,910 --> 00:03:51,840
or how you can configure install

54
00:03:51,860 --> 00:03:59,100
for example with --save versus --save dev to install a production or a development dependency,

55
00:03:59,180 --> 00:04:04,400
if you want to learn more about that, the official docs are of course the right place. There if you

56
00:04:04,400 --> 00:04:06,920
dive in,

57
00:04:06,930 --> 00:04:12,360
you can learn way more about npm and diving deeply into that would really be beyond the scope of this

58
00:04:12,360 --> 00:04:19,530
course because npm creating and managing packages, that is a topic on its own not closely related to

59
00:04:19,550 --> 00:04:23,600
nodejs the language, just an additional feature you get for free,

60
00:04:23,670 --> 00:04:29,460
so here you can learn way more about that and here on this page if you scroll down a bit further, you'll

61
00:04:29,460 --> 00:04:32,470
also see all available commands you could run

62
00:04:32,670 --> 00:04:40,520
and then if you click on one of them, for example uninstall, you also see how you may use it.

63
00:04:40,520 --> 00:04:46,160
So here you see detailed instructions on how you may configure it, for example that you can run it

64
00:04:46,160 --> 00:04:53,180
in global mode to install a package on your system and not just in a project or that you can of course

65
00:04:53,240 --> 00:05:01,850
also install it with the --save flag save dev or save prod which is the same as just

66
00:05:01,850 --> 00:05:03,090
--save in the end,

67
00:05:03,290 --> 00:05:08,910
so there you see all the ways of configuring that or running that command in different ways

68
00:05:08,990 --> 00:05:11,170
and if you want to learn way more about that

69
00:05:11,330 --> 00:05:18,910
and for most cases, you just need npm install --save or --save dev or -g

70
00:05:18,980 --> 00:05:24,090
but if you want to learn way more, of course these official docs are the place to go.

71
00:05:25,140 --> 00:05:31,680
It is worth pointing out that you also can get help here locally, when you type npm help here,

72
00:05:31,890 --> 00:05:38,490
you also get instructions on the available commands you may run and you can also get help on a specific

73
00:05:38,490 --> 00:05:39,310
command.

74
00:05:39,330 --> 00:05:45,400
So if I run npm install --help here or just -h,

75
00:05:45,720 --> 00:05:53,580
then I see how I may run this command and also which options I have to add additional flags.

76
00:05:53,610 --> 00:05:58,270
However these are just the common options, not all options, for the full docs of course,

77
00:05:58,320 --> 00:06:02,590
you should dive into the official documentation here.

78
00:06:02,630 --> 00:06:08,540
The commands you can run here especially installing are one powerful thing

79
00:06:08,600 --> 00:06:09,830
npm allows you to do,

80
00:06:09,830 --> 00:06:15,170
you can add any package you want to your project. Another important feature is that if you click on

81
00:06:15,170 --> 00:06:22,190
using npm here, you can run scripts with npm and that generally is related to that package.json

82
00:06:22,190 --> 00:06:30,050
file you get when you put a project under control of npm which you do with help of the npm init command,

83
00:06:30,050 --> 00:06:35,070
we also use that in that course. That will ask you a couple of questions and then give you a package.json

84
00:06:35,090 --> 00:06:41,870
file which you can use to configure a project and there you can not only keep a list of your dependencies,

85
00:06:41,870 --> 00:06:49,310
you can also add certain scripts and you can run these scripts either with npm start to run the start

86
00:06:49,310 --> 00:06:53,770
script or npm run and then any script name you configured in there

87
00:06:54,080 --> 00:07:01,040
and that is very powerful especially when it comes to using npm and nodejs to build projects.

88
00:07:01,040 --> 00:07:04,280
It is something I can best show in the react application

89
00:07:04,280 --> 00:07:06,600
we worked with in this course.

90
00:07:06,670 --> 00:07:12,580
Here I am in that application and there if we had a look at that package.json file, you see that

91
00:07:12,580 --> 00:07:16,540
scripts area and there you see a couple of scripts which you can run,

92
00:07:16,540 --> 00:07:20,220
for example start with npm start but that's a special case,

93
00:07:20,230 --> 00:07:27,880
all other scripts with npm run and then for example, build or eject and then these scripts are executed.

94
00:07:27,940 --> 00:07:30,950
Now these scripts actually use a third party package,

95
00:07:31,000 --> 00:07:36,790
so a dependency which was installed, react scripts we see it here in the dependencies list and then

96
00:07:36,790 --> 00:07:42,130
that dependency holds the code that will actually do something and that is the next step I will come

97
00:07:42,130 --> 00:07:50,020
back to with nodejs being able to run on your machine and not being limited to spinning up a web server.
