Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed npm Basics!
You have completed npm Basics!
Preview
Semantic Version is a system for communicating changes in versions of projects.
Further Reading
Semantic Versioning
MAJOR.MINOR.PATCH
-
^
before a version number means install up to the latestMINOR
release.- e.g.
^1.1
can install1.3
if available but not2.0
- e.g.
-
~
before a version number means install up to the latestPATCH
release.- e.g.
~2.0.1
can install2.0.9
if available but not2.1.0
- e.g.
Terminal Commands
- Clear the screen
clear
npm Command Line Usage
-
See list of commands
npm
-
Installing a packages from
package.json
npm install
-
Check for outdated packages
npm outdated
-
Update packages in your project
- For local packages
npm update
- For global packages
npm update <package name> -g
- e.g.
npm update http-server -g
- e.g.
- For local packages
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You may begin to notice that NPM
packages are often referred to by
0:00
a combination of the name of the package
followed by a version number.
0:04
An individual package can
have hundreds of versions and
0:10
between these versions there
may be small or large changes.
0:15
Some versions may be fixes of
bugs from previous versions.
0:19
Some newer versions would break projects
that rely on previous versions.
0:24
We can gather all of this
information from the version number.
0:30
[SOUND] Package version numbers, consist
of three numbers, separated by periods.
0:35
This style of numbering is called
semantic versioning or SemVer for short.
0:43
NPM relies on semantic versioning to
communicate differences in updates,
0:48
determine which packages to install,
and more.
0:53
The first number is
the major version number.
0:57
This changes for example, when a project
goes from version one to version two,
1:01
it means there are breaking changes.
1:07
Breaking changes mean that an app
using v1 might break when the package
1:09
is updated to v2.
1:14
The second number is for
minor or patch changes.
1:15
From version 1.1 to 1.2,
there may be small changes that
1:20
shouldn't affect apps
relying on previous versions.
1:25
Finally, the last number
represents bug fixes.
1:30
These are normally small fixes of
bugs from previous versions that
1:35
shouldn't have any other effects.
1:39
Along with version numbers,
semantic versioning uses symbols to
1:41
indicate ranges of acceptable
versions of a package.
1:46
We'll learn more about installing
packages in the next video.
1:50
But let's first turn our attention to
these symbols and how we use them.
1:54
The caret symbol is used to refer to all
greater versions in the same major range.
2:01
With the caret, there can be minor
differences in versions, but
2:08
nothing should break.
2:11
The tilde refers to all versions greater
2:13
than a given version in
the same minor range.
2:16
This means all versions greater
than the given version that have
2:20
the same middle digit.
2:24
We can also define ranges using
greater than, less than and
2:28
other comparison operators.
2:32
We can use a tool called semver
calculator to visualize all of this.
2:35
We give semver calculator a package
name and a version number.
2:39
Here it has a popular JavaScript
utility library lodash.
2:44
We'll borrow the rain
from the example below.
2:52
When we enter a range using
a caret in the number 2.2.1,
3:02
all of the minor updates
after 2.2.1 are highlighted.
3:07
Changing this to a tilde highlights
the single bug update for version 2.2.
3:18
The greater than or equal sign gives
us a range of everything beyond and
3:23
including 2.21.
3:29
Notice if we type 0.0,
3:35
most of the packages are highlighted,
but some are not.
3:38
This is because by default,
pre release versions are not included.
3:45
These versions may have experimental
features that aren't added for
3:50
the long term.
3:54
Because of this,
3:56
you'll generally want to avoid using
these versions in production code.
3:57
To review, [SOUND] major changes
are the most important to watch out for
4:03
and may require refactoring.
4:08
Minor changes typically
won't affect your apps.
4:10
Bug fixes are usually beneficial and
4:13
shouldn't have any other
effects on your apps.
4:15
Knowing more about versioning we
can better decide which package and
4:19
version to include in our projects.
4:23
In the upcoming videos, where we learn
more about working with packages,
4:26
we'll also learn how we can install or
update to a specific version of a package.
4:30
This will give you more control over
exactly which code you're using
4:36
in your apps.
4:40
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up