Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,260 --> 00:00:02,200
In this lecture,
2
00:00:02,200 --> 00:00:03,783
we're going to talk about a bunch of
3
00:00:03,783 --> 00:00:05,980
more stuff that you should know
4
00:00:05,980 --> 00:00:08,630
about working with npm packages,
5
00:00:08,630 --> 00:00:13,610
such as versioning, updating, or deleting packages,
6
00:00:13,610 --> 00:00:17,043
and also some other stuff, so let's get started.
7
00:00:18,860 --> 00:00:20,670
The first thing that I want to talk about
8
00:00:20,670 --> 00:00:25,670
in this video is these version numbers of our packages.
9
00:00:26,000 --> 00:00:28,110
Most of the packages on npm
10
00:00:28,110 --> 00:00:31,510
follow the so-called semantic version notation,
11
00:00:31,510 --> 00:00:34,140
which means that their versions numbers
12
00:00:34,140 --> 00:00:36,913
is always expressed with these three numbers.
13
00:00:38,010 --> 00:00:41,000
The first one here is called the major version.
14
00:00:41,000 --> 00:00:44,190
The second one is called the minor version.
15
00:00:44,190 --> 00:00:47,460
The third one is called the patch version.
16
00:00:47,460 --> 00:00:51,604
There's actually a meaning in these three numbers.
17
00:00:51,604 --> 00:00:55,160
The patch version, which is just this last one here,
18
00:00:55,160 --> 00:00:58,080
is only intended to fix bugs.
19
00:00:58,080 --> 00:01:01,750
Let's say that in version 1.18,
20
00:01:01,750 --> 00:01:04,150
the developers found a bug and so
21
00:01:04,150 --> 00:01:08,663
they fixed that bug and then released 1.18.1.
22
00:01:09,860 --> 00:01:11,320
Then they found another bug
23
00:01:11,320 --> 00:01:14,840
and then they released 1.18.2
24
00:01:14,840 --> 00:01:18,843
and so on and so forth until they reached 1.18.11,
25
00:01:20,350 --> 00:01:22,203
which is the current version number.
26
00:01:23,450 --> 00:01:27,140
Again, this last one here is just for bug fixes.
27
00:01:27,140 --> 00:01:31,040
Then after that, we have the minor version.
28
00:01:31,040 --> 00:01:32,670
The minor version introduces
29
00:01:32,670 --> 00:01:35,130
some new features into the package,
30
00:01:35,130 --> 00:01:38,170
but it does not include breaking changes.
31
00:01:38,170 --> 00:01:41,270
All the changes that are done in a new version number
32
00:01:41,270 --> 00:01:43,593
will always be backward-compatible.
33
00:01:44,751 --> 00:01:47,410
If one day the nodemon team, for example,
34
00:01:47,410 --> 00:01:51,290
decides to release version 1.19,
35
00:01:51,290 --> 00:01:54,110
well, that will then include some new features
36
00:01:54,110 --> 00:01:56,570
but it will not break our code.
37
00:01:56,570 --> 00:01:59,750
And the same of course happens with this one here.
38
00:01:59,750 --> 00:02:03,230
So if some day, there is Slugify 1.4,
39
00:02:03,230 --> 00:02:06,190
well then our code is still going to work the same.
40
00:02:06,190 --> 00:02:08,320
There will not be any breaking changes.
41
00:02:08,320 --> 00:02:10,600
Simply there will be something new,
42
00:02:10,600 --> 00:02:14,947
so some new features, which are not just bug fixes.
43
00:02:14,947 --> 00:02:17,940
Bug fixes again are for the third,
44
00:02:17,940 --> 00:02:19,850
so for the patch version,
45
00:02:19,850 --> 00:02:23,870
and then minor new features are for the minor version.
46
00:02:23,870 --> 00:02:26,620
Then of course, we have the major version,
47
00:02:26,620 --> 00:02:28,840
which is only bumped up whenever it is
48
00:02:28,840 --> 00:02:33,140
a huge new release which can have breaking changes.
49
00:02:33,140 --> 00:02:36,500
For example, if Slugify 2 comes along.
50
00:02:36,500 --> 00:02:39,000
Well our code might no longer work
51
00:02:39,000 --> 00:02:42,130
because the slugify function that we have here
52
00:02:42,130 --> 00:02:44,856
for example, might have changed its name
53
00:02:44,856 --> 00:02:48,940
or maybe the parameter that it expects here are different
54
00:02:48,940 --> 00:02:51,240
or the options might have changed,
55
00:02:51,240 --> 00:02:53,210
or something might have changed
56
00:02:53,210 --> 00:02:55,123
that will break previous version.
57
00:02:57,040 --> 00:02:59,720
Be aware that when there is a new version,
58
00:02:59,720 --> 00:03:02,020
it might usually affect
59
00:03:02,020 --> 00:03:03,570
the code that you already have.
60
00:03:05,030 --> 00:03:07,300
Because of that, it is also important
61
00:03:07,300 --> 00:03:09,823
to talk about updating packages.
62
00:03:10,670 --> 00:03:12,620
In our package.json file,
63
00:03:12,620 --> 00:03:15,258
this small symbol here that comes in front
64
00:03:15,258 --> 00:03:18,460
of the version number is what specifies
65
00:03:18,460 --> 00:03:22,363
which updates we accept for each of the packages.
66
00:03:23,290 --> 00:03:27,430
This symbol here, which npm specifies here by default
67
00:03:27,430 --> 00:03:31,900
means that we accept patch and minor releases.
68
00:03:31,900 --> 00:03:34,890
Now, how do we actually update packages?
69
00:03:34,890 --> 00:03:39,080
Well, let's actually quit this process here.
70
00:03:39,080 --> 00:03:40,580
The first thing that we can do
71
00:03:40,580 --> 00:03:44,120
is to check if there are any outdated packages.
72
00:03:44,120 --> 00:03:49,120
We write npm outdated, and that should then give us
73
00:03:49,720 --> 00:03:51,530
actually a table with all
74
00:03:51,530 --> 00:03:53,125
the packages that are outdated.
75
00:03:53,125 --> 00:03:55,970
Well right now, they're all up-to-date,
76
00:03:55,970 --> 00:03:57,860
so that didn't really happen.
77
00:03:57,860 --> 00:03:59,021
What I want to show you now
78
00:03:59,021 --> 00:04:01,550
is that we can actually install
79
00:04:01,550 --> 00:04:05,240
a certain package with a certain version number.
80
00:04:05,240 --> 00:04:06,945
Let's do that with the Slugify
81
00:04:06,945 --> 00:04:11,003
and install it at version 1.0.0.
82
00:04:13,980 --> 00:04:18,980
Npm install slugify and then at 1.0.0.
83
00:04:22,220 --> 00:04:23,233
Let's try that out.
84
00:04:25,645 --> 00:04:29,560
Now indeed, we have one zero zero.
85
00:04:29,560 --> 00:04:31,740
When we hover it, it actually says
86
00:04:31,740 --> 00:04:35,773
latest version 1.3.4, which is what we had.
87
00:04:36,660 --> 00:04:40,630
But if we now run npm outdated,
88
00:04:40,630 --> 00:04:43,390
it should then give us that.
89
00:04:43,390 --> 00:04:46,360
We see that current is 1.0.0.
90
00:04:46,360 --> 00:04:50,642
Wanted is 1.3.4, because that is the one that we accept
91
00:04:50,642 --> 00:04:53,060
because remember, that with this here,
92
00:04:53,060 --> 00:04:56,820
we accept all the patch and all the minor releases,
93
00:04:56,820 --> 00:04:59,821
but of course, we can also change that.
94
00:04:59,821 --> 00:05:04,580
For example, we can set it to this symbol here.
95
00:05:04,580 --> 00:05:07,860
This will then only accept patch releases.
96
00:05:07,860 --> 00:05:09,483
This one is a bit safer.
97
00:05:10,960 --> 00:05:13,570
If we run npm outdated now again,
98
00:05:13,570 --> 00:05:14,693
let's see what we get.
99
00:05:15,590 --> 00:05:19,150
Now the wanted is only 1.0.2,
100
00:05:19,150 --> 00:05:22,690
because again, we only accept minor versions.
101
00:05:22,690 --> 00:05:26,090
So 1.3.4 is not accepted by us
102
00:05:26,090 --> 00:05:28,670
because well, we do not accept
103
00:05:28,670 --> 00:05:30,820
any of the minor releases,
104
00:05:30,820 --> 00:05:33,670
so again, just patch releases.
105
00:05:33,670 --> 00:05:38,670
If you were to do npm update slugify now,
106
00:05:41,460 --> 00:05:42,903
let's see what we got then.
107
00:05:45,360 --> 00:05:48,440
Now we're at 1.0.2.
108
00:05:48,440 --> 00:05:49,537
You see that it changed back
109
00:05:49,537 --> 00:05:52,930
for my updating configuration here
110
00:05:52,930 --> 00:05:56,360
to accept minor and patch releases.
111
00:05:56,360 --> 00:05:58,763
Not just the patch releases like we had before.
112
00:06:01,010 --> 00:06:02,820
If we're going to run this now again,
113
00:06:02,820 --> 00:06:04,180
it should actually bump us up
114
00:06:04,180 --> 00:06:08,163
all the way to 1.3.4, like we had before.
115
00:06:09,710 --> 00:06:11,343
Indeed, here we go.
116
00:06:12,550 --> 00:06:16,060
All right, that is how we update packages.
117
00:06:16,060 --> 00:06:18,240
There are other configurations
118
00:06:18,240 --> 00:06:20,040
that we can choose here.
119
00:06:20,040 --> 00:06:23,070
We can say, for example, that we want
120
00:06:23,070 --> 00:06:25,970
all of the versions, so if at some point,
121
00:06:25,970 --> 00:06:28,790
there is a version two and if we didn't update
122
00:06:28,790 --> 00:06:30,930
our packages, it will then automatically
123
00:06:30,930 --> 00:06:33,633
bump our version up to version two.
124
00:06:34,590 --> 00:06:36,903
This one includes all the versions,
125
00:06:38,259 --> 00:06:40,880
even ones with breaking changes.
126
00:06:40,880 --> 00:06:43,530
But that's not a good idea usually,
127
00:06:43,530 --> 00:06:46,330
and so I usually just go with this one
128
00:06:46,330 --> 00:06:49,510
that is default, or sometimes even this one here
129
00:06:49,510 --> 00:06:52,740
because at some point, even if a minor release
130
00:06:52,740 --> 00:06:54,880
should simply introduce new features
131
00:06:54,880 --> 00:06:57,690
but no breaking changes, we know that sometimes
132
00:06:57,690 --> 00:07:00,490
there can be bugs that developers do not found,
133
00:07:00,490 --> 00:07:02,270
and then these bugs, they find their way
134
00:07:02,270 --> 00:07:05,010
into our code and might break our code.
135
00:07:05,010 --> 00:07:07,600
We do not want that, of course.
136
00:07:07,600 --> 00:07:09,700
The safest version is to just
137
00:07:09,700 --> 00:07:12,149
use this one for bug fixes.
138
00:07:12,149 --> 00:07:15,510
Let's actually just keep it like this here,
139
00:07:15,510 --> 00:07:17,783
just for demonstration purposes.
140
00:07:19,183 --> 00:07:20,950
This is what you need to know about
141
00:07:20,950 --> 00:07:23,123
version numbers and updating.
142
00:07:24,030 --> 00:07:26,443
But we can of course also delete packages.
143
00:07:27,350 --> 00:07:30,493
Let's now go ahead and install Express,
144
00:07:36,280 --> 00:07:40,140
so that we can then go ahead and delete it after that.
145
00:07:40,140 --> 00:07:43,000
I'm sure that you can guess how we can do that.
146
00:07:43,000 --> 00:07:44,960
That is very easy.
147
00:07:44,960 --> 00:07:49,620
Npm uninstall, so it's actually not called delete.
148
00:07:49,620 --> 00:07:51,510
It's really uninstalling.
149
00:07:51,510 --> 00:07:56,303
We install and we uninstall Express.
150
00:07:58,170 --> 00:08:00,460
That will then delete it from
151
00:08:00,460 --> 00:08:02,941
our node modules folder, and also from
152
00:08:02,941 --> 00:08:05,960
our dependencies in a package.json file.
153
00:08:06,920 --> 00:08:11,000
Each time we decide not to use a module anymore,
154
00:08:11,000 --> 00:08:14,140
well, we should always go ahead and remove it,
155
00:08:14,140 --> 00:08:15,983
or actually uninstall it.
156
00:08:16,900 --> 00:08:19,450
Now as a final thing, I want to talk a little bit
157
00:08:19,450 --> 00:08:22,240
about the node modules folder.
158
00:08:22,240 --> 00:08:24,010
This folder, which contains all
159
00:08:24,010 --> 00:08:26,600
the dependencies of our project.
160
00:08:26,600 --> 00:08:29,210
Let's say that you want to share your code
161
00:08:29,210 --> 00:08:31,393
with someone, or that you, for example,
162
00:08:31,393 --> 00:08:33,549
want to start working on one computer
163
00:08:33,549 --> 00:08:35,850
and then move to the next one.
164
00:08:35,850 --> 00:08:39,140
You will never share this node modules folder
165
00:08:39,140 --> 00:08:42,330
because this code, you can easily get it from npm.
166
00:08:42,330 --> 00:08:44,570
There's no need to go ahead and copy
167
00:08:44,570 --> 00:08:46,760
all of this code here, for example,
168
00:08:46,760 --> 00:08:50,730
to a GitHub repository or to a Dropbox folder,
169
00:08:50,730 --> 00:08:54,040
or really somewhere that you want to share your code,
170
00:08:54,040 --> 00:08:56,000
because this folder here as you see
171
00:08:56,000 --> 00:08:58,616
has tons of folders and each of them
172
00:08:58,616 --> 00:09:01,670
might have tons of files.
173
00:09:01,670 --> 00:09:03,670
All of a sudden, you might end up with
174
00:09:03,670 --> 00:09:06,313
tens or hundreds of thousands of files.
175
00:09:07,718 --> 00:09:09,860
You should never share this folder
176
00:09:09,860 --> 00:09:13,173
and never check it out into your GitHub repository.
177
00:09:14,680 --> 00:09:17,620
Let's say that you uploaded this code
178
00:09:17,620 --> 00:09:21,173
to your GitHub account without this node modules,
179
00:09:22,580 --> 00:09:25,020
or you put it into a Dropbox on one computer
180
00:09:25,020 --> 00:09:27,660
and downloaded it at the other one.
181
00:09:27,660 --> 00:09:30,464
Let's say we now downloaded this code here,
182
00:09:30,464 --> 00:09:32,780
so without node modules.
183
00:09:32,780 --> 00:09:34,540
So we delete that one now
184
00:09:36,050 --> 00:09:38,523
and end up with just a regular project folder.
185
00:09:39,720 --> 00:09:42,092
How do we now get back our dependencies
186
00:09:42,092 --> 00:09:44,180
or our node modules folder?
187
00:09:44,180 --> 00:09:46,120
Well, it's very easy.
188
00:09:46,120 --> 00:09:48,503
All we have to do is npm install.
189
00:09:55,490 --> 00:09:58,950
What it did is to read our package.json file,
190
00:09:58,950 --> 00:10:02,030
read our dependencies, and then download everything
191
00:10:02,030 --> 00:10:05,860
back into this folder, all right.
192
00:10:05,860 --> 00:10:07,940
Now one important piece of this puzzle
193
00:10:07,940 --> 00:10:10,503
is the package-lock.json file.
194
00:10:12,290 --> 00:10:15,070
If we open that up, we get a list of
195
00:10:15,070 --> 00:10:17,710
all the versions of all the packages
196
00:10:17,710 --> 00:10:19,210
that we're actually using.
197
00:10:19,210 --> 00:10:22,093
That includes the dependencies of our dependencies.
198
00:10:23,100 --> 00:10:25,373
Let's go to Slugify, for example.
199
00:10:28,030 --> 00:10:29,910
Slugify, and so here we see that
200
00:10:29,910 --> 00:10:31,413
we're using version 1.3.4.
201
00:10:33,270 --> 00:10:35,600
That is very important because
202
00:10:35,600 --> 00:10:38,420
if you share your code, you want the other developer
203
00:10:38,420 --> 00:10:40,190
or even yourself to be using
204
00:10:40,190 --> 00:10:42,450
the exact same package versions,
205
00:10:42,450 --> 00:10:45,760
so that your code works the exact same way for you
206
00:10:45,760 --> 00:10:47,300
and for the other developer.
207
00:10:47,300 --> 00:10:50,200
For that, the exact version numbers
208
00:10:50,200 --> 00:10:52,380
are basically set in stone
209
00:10:52,380 --> 00:10:54,833
in this package-lock.json file.
210
00:10:56,624 --> 00:10:58,850
If you share your code, no matter if you're using
211
00:10:58,850 --> 00:11:02,180
GitHub or Dropbox or something like that,
212
00:11:02,180 --> 00:11:04,690
always share your package.json file
213
00:11:04,690 --> 00:11:07,660
and the package-lock.json file
214
00:11:07,660 --> 00:11:09,690
because these two files are necessary
215
00:11:09,690 --> 00:11:12,460
for the other developer to then reconstruct
216
00:11:12,460 --> 00:11:15,143
basically the node modules folder.
217
00:11:18,232 --> 00:11:20,860
Yeah, I think that's all you need to know
218
00:11:20,860 --> 00:11:23,600
about package versions, updating,
219
00:11:23,600 --> 00:11:28,230
uninstalling, and also sharing code with npm,
220
00:11:28,230 --> 00:11:31,710
package.json and package-lock.json.
221
00:11:31,710 --> 00:11:33,870
If there's anything more that you want to know,
222
00:11:33,870 --> 00:11:37,320
you can again always ask in the course Q and A
223
00:11:37,320 --> 00:11:39,323
and then you'll get help there.
17157
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.