1
00:00:00,210 --> 00:00:05,760
All right welcome back and this video we're finally going to talk about what the dash dash to save flag

2
00:00:05,760 --> 00:00:08,120
means when we do NPM install.

3
00:00:08,150 --> 00:00:12,930
I had initially intended for this to be at the end of the last video but because of time constraints

4
00:00:12,960 --> 00:00:17,680
as I started recording this I realized that there was some more detail that we needed to talk about

5
00:00:17,700 --> 00:00:21,450
and a few other components that I wanted to bring into the discussion and that it made sense for it

6
00:00:21,450 --> 00:00:23,610
to be a standalone video.

7
00:00:23,610 --> 00:00:29,790
So the objectives here are to use the dash dash save flag to install packages and understand what it

8
00:00:29,790 --> 00:00:30,720
means.

9
00:00:30,750 --> 00:00:34,720
Explain what the package that Jason filed does and then use another command.

10
00:00:34,740 --> 00:00:37,150
NPM and knit to create a new package.

11
00:00:37,980 --> 00:00:41,200
Let's start by talking about this file package Scott J song.

12
00:00:41,310 --> 00:00:47,390
And to do that I'm going to open up a nice blog post on the blog of a company called Noj it too and

13
00:00:47,430 --> 00:00:53,310
this post explains what the package that just on file is every single NPM package that we've used and

14
00:00:53,310 --> 00:00:57,840
that we will use in the future has a file called package J song.

15
00:00:58,260 --> 00:01:04,410
So I can show you that first if we look at our first express app and we look in the Express directory

16
00:01:04,770 --> 00:01:10,370
there is a file called package that Jason and we're going to discuss Jason later on.

17
00:01:10,380 --> 00:01:12,630
It stands for a javascript object notation.

18
00:01:12,780 --> 00:01:18,270
It's just a data type is a way of formatting text in a file to represent structure.

19
00:01:18,480 --> 00:01:25,020
And what this is is a file that contains all the meta data about this particular application or this

20
00:01:25,020 --> 00:01:32,940
package express so it contains a description a name an author and then all the different contributors

21
00:01:33,000 --> 00:01:34,780
who have added to it.

22
00:01:34,800 --> 00:01:42,330
It also contains the license the get hub repository you are l the homepage so it can be used to search

23
00:01:42,330 --> 00:01:45,550
for it and probably most importantly the dependencies.

24
00:01:45,660 --> 00:01:50,100
These are all the packages that express relies on that it needs in order to work.

25
00:01:50,100 --> 00:01:52,010
And there is quite a few of them as you can see here.

26
00:01:52,260 --> 00:01:54,050
And this file will collect them all.

27
00:01:54,210 --> 00:01:57,600
And also explains the versions that are needed.

28
00:01:57,630 --> 00:02:04,110
So that's what the package that some file is it holds metadata relevant to a specific project and I'll

29
00:02:04,110 --> 00:02:05,400
show you one more example.

30
00:02:05,400 --> 00:02:09,240
This is actually the same package that Jason but this one is on get help.

31
00:02:09,360 --> 00:02:11,750
It's on the Express repository.

32
00:02:11,790 --> 00:02:15,270
So this is the Express code itself being hosted on get help.

33
00:02:15,810 --> 00:02:21,340
And we have a package such a song and inside of that here's all the same data that we just saw.

34
00:02:21,590 --> 00:02:27,750
But the reason I'm showing it to you is that you might notice that the node modules directory is actually

35
00:02:27,750 --> 00:02:34,740
not included it's not on get help but it is included when we go and look at Express right here instead

36
00:02:34,740 --> 00:02:40,460
of Express we have lib and node modules and then package stuff Jason and a few other things I don't

37
00:02:40,500 --> 00:02:43,890
get how there's just lib and node modules.

38
00:02:43,890 --> 00:02:45,110
It's nowhere to be found.

39
00:02:45,270 --> 00:02:51,210
And that's for a very particular reason which is that when we're sharing code and packages and repositories

40
00:02:51,210 --> 00:02:58,350
are big projects and they depend on 10 20 or even 100 other packages rather than uploading all of these

41
00:02:58,350 --> 00:03:03,210
packages with the rest of our code we can just put them in the package store J song.

42
00:03:03,450 --> 00:03:08,820
And then when someone installs Express and someone downloads this or fork's this repository it makes

43
00:03:08,820 --> 00:03:09,630
their own copy.

44
00:03:09,630 --> 00:03:11,110
And they want to use it.

45
00:03:11,160 --> 00:03:15,360
They'll see what they need to install but they won't download all of the baggage that goes along with

46
00:03:15,360 --> 00:03:16,530
this automatically.

47
00:03:16,740 --> 00:03:22,260
Luckily there's also a really easy command to automatically install everything inside the package such

48
00:03:22,260 --> 00:03:28,710
Esan under dependencies and we'll also see that later on I came up with a silly analogy to help explain

49
00:03:28,980 --> 00:03:30,140
this idea of the pack.

50
00:03:30,230 --> 00:03:33,390
Jaison and in particular the dependency section.

51
00:03:33,690 --> 00:03:38,700
So imagine that you have a great recipe a great dish that you make and I want my friend in Denmark to

52
00:03:38,700 --> 00:03:41,750
be able to replicate the meal that I can make here in California.

53
00:03:42,030 --> 00:03:47,200
So one option would be for me to go buy all of the ingredients for him package them all up pre-measured

54
00:03:47,310 --> 00:03:52,710
everything put it in Ziploc bags and then put everything in a big box add in some instructions on how

55
00:03:52,710 --> 00:03:54,240
to cook them.

56
00:03:54,390 --> 00:03:57,190
Throw in some instructions on how to cook the meal.

57
00:03:57,210 --> 00:04:02,250
Tape it all up and then go to the post office and pay a lot of money to ship it to my friend in Denmark

58
00:04:02,260 --> 00:04:02,400
.

59
00:04:02,550 --> 00:04:05,150
The alternative is just to send my friend a letter.

60
00:04:05,370 --> 00:04:09,490
And in that letter we'll just describe the ingredients and the quantities that are needed.

61
00:04:09,750 --> 00:04:14,280
And then once that letter gets to Denmark my friend can figure out what he needs to buy what he already

62
00:04:14,280 --> 00:04:18,100
has how much he needs everything and he can prepare the meal on his own.

63
00:04:18,360 --> 00:04:20,060
Hopefully you can see where I'm going with this.

64
00:04:20,130 --> 00:04:25,110
The way that the package that Jason works is that it's the recipe for the ingredients that are needed

65
00:04:25,110 --> 00:04:31,710
for a specific package or library rather than sending the contents of all of these individual packages

66
00:04:31,710 --> 00:04:32,000
.

67
00:04:32,160 --> 00:04:37,700
We just send a package that Jason that is basically a shopping list for all the packages and whoever's

68
00:04:37,710 --> 00:04:43,310
using that package can then easily go and install all of these sort of up all that up.

69
00:04:43,410 --> 00:04:49,830
Peggy Stut Jaison contains a bunch of metadata about a particular application or package and that ranges

70
00:04:49,830 --> 00:04:55,950
from things like the name of it the description of version number all the way down to the dependencies

71
00:04:56,400 --> 00:04:58,930
which in my mind is the most important aspect.

72
00:04:58,950 --> 00:05:04,110
It contains a list of packages and the version number of each package that's needed in order for this

73
00:05:04,110 --> 00:05:05,560
application to run.

74
00:05:06,090 --> 00:05:09,840
So that brings me to the next point which is what does a dash dash save do.

75
00:05:10,350 --> 00:05:15,260
When we install a package with NPM install and we add on this flag at the end.

76
00:05:15,390 --> 00:05:22,230
Dash dash save it will take the package name and version in automatically save it into our package JS

77
00:05:22,270 --> 00:05:23,950
on file if we have one.

78
00:05:24,210 --> 00:05:31,860
Oh quickly demonstrate that we are to make a new directory and I'm just going to call this package.

79
00:05:32,060 --> 00:05:36,090
On demo and then CD into that.

80
00:05:36,930 --> 00:05:42,300
And the first thing I need to do is create a package that JS on file and I can do that myself by doing

81
00:05:42,600 --> 00:05:47,380
touch package that Jason and then filling out all those fields.

82
00:05:47,430 --> 00:05:52,830
But there's an easier way which is this third little bullet point here using NPM and need to create

83
00:05:52,830 --> 00:05:54,730
a package Duguay some for us.

84
00:05:55,020 --> 00:06:02,030
So go down to my terminal and type NPM in it inside of the folder where I want my application to exist

85
00:06:02,460 --> 00:06:04,340
in this case package based on demo.

86
00:06:04,440 --> 00:06:07,800
I'll hit enter and I get this message printed out to me.

87
00:06:08,070 --> 00:06:12,380
It says this utility will walk you through creating a package dot JSON file.

88
00:06:12,390 --> 00:06:16,070
Basically it asks me a bunch of questions like what's the name of my package.

89
00:06:16,200 --> 00:06:20,350
And then I type it in and then hit Enter when I'm done and we'll ask me another question and then we

90
00:06:20,370 --> 00:06:24,070
use all that data to make our package that Jason at the very end.

91
00:06:24,570 --> 00:06:29,370
So for name it's guessing that we want to call it package to chase on demo because that's the name of

92
00:06:29,370 --> 00:06:30,260
the folder we're in.

93
00:06:30,330 --> 00:06:31,050
Which is fine.

94
00:06:31,110 --> 00:06:33,780
So we can just hit enter and it will use that.

95
00:06:33,780 --> 00:06:39,600
Same thing with version if I just hit enter it will use version 1.0 0.00 does need to be in this format

96
00:06:39,660 --> 00:06:40,890
of some number.

97
00:06:40,920 --> 00:06:44,750
Another number another number description.

98
00:06:44,950 --> 00:06:52,980
Well just do simple package that J some demo entry point refers to the file where application starts

99
00:06:53,370 --> 00:06:56,420
and in most of our applications it's going to be apt.

100
00:06:56,520 --> 00:06:56,980
Yes.

101
00:06:57,210 --> 00:06:59,730
And that's just a personal preference in this case.

102
00:06:59,730 --> 00:07:01,690
We're not really going to have an application at all.

103
00:07:01,710 --> 00:07:04,890
We're just installing packages just to show you how it works.

104
00:07:04,950 --> 00:07:11,820
So we can put whatever we want we'll hit enter from test command and get repository keywords as well

105
00:07:11,820 --> 00:07:11,880
.

106
00:07:11,880 --> 00:07:19,140
We're not going to enter any of that for author can put in cold steel license and just use the default

107
00:07:19,140 --> 00:07:23,930
one and you can see it shows me a little preview of what it's going to do and then it.

108
00:07:23,970 --> 00:07:24,790
Is that OK.

109
00:07:24,990 --> 00:07:26,670
I'll get yes or enter.

110
00:07:26,910 --> 00:07:31,410
And now if I type LS I have a new file package such a song.

111
00:07:31,440 --> 00:07:38,790
So here's the package that Jason move it up here you can see it has our name and our version and everything

112
00:07:38,790 --> 00:07:39,560
else that we did.

113
00:07:39,750 --> 00:07:42,600
But it doesn't have any dependencies yet.

114
00:07:42,600 --> 00:07:46,320
So now let's go and install a new package will do express.

115
00:07:46,380 --> 00:07:54,570
So we just run NPM install express and then dash dash save at the end and hit enter.

116
00:07:55,290 --> 00:07:59,930
And you see we now end up with a dependancies field here and it has.

117
00:07:59,940 --> 00:08:04,910
EXPRESS And then our version 4.1 3.3.

118
00:08:05,160 --> 00:08:15,400
And we can install another package like Cat me dash dash save and it adds that into Pakistan based on

119
00:08:15,450 --> 00:08:18,150
under dependencies as well.

120
00:08:18,150 --> 00:08:20,490
All right so let's wrap up the package.

121
00:08:20,520 --> 00:08:24,810
Jason file contains metadata about an application order package.

122
00:08:24,840 --> 00:08:29,760
It's really really common to see them and really common for us to create our own package that Jaison

123
00:08:30,060 --> 00:08:35,300
using NPM in it for every single app we make from here on out every single real app.

124
00:08:35,310 --> 00:08:37,080
That's not just a quick demonstration.

125
00:08:37,170 --> 00:08:40,550
We'll be using NPM in it and creating a package that Jaison.

126
00:08:40,800 --> 00:08:45,890
And the last important point is that we can use dash dash save when we're installing a package.

127
00:08:45,940 --> 00:08:50,220
Doesn't matter what package any package we just add dash dash save at the end.

128
00:08:50,400 --> 00:08:57,660
And that will install it and then also save it to the dependency section of our package that Jason along

129
00:08:57,660 --> 00:08:59,460
with the version that we installed.

130
00:08:59,800 --> 00:09:00,330
OK.

131
00:09:00,360 --> 00:09:03,090
In the next video we're going to keep moving forward with Express
