1 00:00:00,410 --> 00:00:04,808 You may begin to notice that NPM packages are often referred to by 2 00:00:04,808 --> 00:00:10,470 a combination of the name of the package followed by a version number. 3 00:00:10,470 --> 00:00:15,004 An individual package can have hundreds of versions and 4 00:00:15,004 --> 00:00:19,931 between these versions there may be small or large changes. 5 00:00:19,931 --> 00:00:24,703 Some versions may be fixes of bugs from previous versions. 6 00:00:24,703 --> 00:00:30,626 Some newer versions would break projects that rely on previous versions. 7 00:00:30,626 --> 00:00:35,727 We can gather all of this information from the version number. 8 00:00:35,727 --> 00:00:43,022 [SOUND] Package version numbers, consist of three numbers, separated by periods. 9 00:00:43,022 --> 00:00:48,820 This style of numbering is called semantic versioning or SemVer for short. 10 00:00:48,820 --> 00:00:53,815 NPM relies on semantic versioning to communicate differences in updates, 11 00:00:53,815 --> 00:00:57,870 determine which packages to install, and more. 12 00:00:57,870 --> 00:01:01,360 The first number is the major version number. 13 00:01:01,360 --> 00:01:07,127 This changes for example, when a project goes from version one to version two, 14 00:01:07,127 --> 00:01:09,894 it means there are breaking changes. 15 00:01:09,894 --> 00:01:14,681 Breaking changes mean that an app using v1 might break when the package 16 00:01:14,681 --> 00:01:15,970 is updated to v2. 17 00:01:15,970 --> 00:01:20,304 The second number is for minor or patch changes. 18 00:01:20,304 --> 00:01:25,303 From version 1.1 to 1.2, there may be small changes that 19 00:01:25,303 --> 00:01:29,750 shouldn't affect apps relying on previous versions. 20 00:01:30,790 --> 00:01:35,340 Finally, the last number represents bug fixes. 21 00:01:35,340 --> 00:01:39,596 These are normally small fixes of bugs from previous versions that 22 00:01:39,596 --> 00:01:41,954 shouldn't have any other effects. 23 00:01:41,954 --> 00:01:46,729 Along with version numbers, semantic versioning uses symbols to 24 00:01:46,729 --> 00:01:50,663 indicate ranges of acceptable versions of a package. 25 00:01:50,663 --> 00:01:54,176 We'll learn more about installing packages in the next video. 26 00:01:54,176 --> 00:01:58,491 But let's first turn our attention to these symbols and how we use them. 27 00:02:01,908 --> 00:02:08,190 The caret symbol is used to refer to all greater versions in the same major range. 28 00:02:08,190 --> 00:02:11,805 With the caret, there can be minor differences in versions, but 29 00:02:11,805 --> 00:02:13,129 nothing should break. 30 00:02:13,129 --> 00:02:16,654 The tilde refers to all versions greater 31 00:02:16,654 --> 00:02:20,601 than a given version in the same minor range. 32 00:02:20,601 --> 00:02:24,489 This means all versions greater than the given version that have 33 00:02:24,489 --> 00:02:25,936 the same middle digit. 34 00:02:28,437 --> 00:02:32,346 We can also define ranges using greater than, less than and 35 00:02:32,346 --> 00:02:35,220 other comparison operators. 36 00:02:35,220 --> 00:02:39,661 We can use a tool called semver calculator to visualize all of this. 37 00:02:39,661 --> 00:02:44,572 We give semver calculator a package name and a version number. 38 00:02:44,572 --> 00:02:48,794 Here it has a popular JavaScript utility library lodash. 39 00:02:52,244 --> 00:02:54,913 We'll borrow the rain from the example below. 40 00:03:02,539 --> 00:03:07,231 When we enter a range using a caret in the number 2.2.1, 41 00:03:07,231 --> 00:03:11,932 all of the minor updates after 2.2.1 are highlighted. 42 00:03:18,510 --> 00:03:23,862 Changing this to a tilde highlights the single bug update for version 2.2. 43 00:03:23,862 --> 00:03:29,467 The greater than or equal sign gives us a range of everything beyond and 44 00:03:29,467 --> 00:03:31,275 including 2.21. 45 00:03:35,730 --> 00:03:38,128 Notice if we type 0.0, 46 00:03:38,128 --> 00:03:43,360 most of the packages are highlighted, but some are not. 47 00:03:45,330 --> 00:03:49,540 This is because by default, pre release versions are not included. 48 00:03:50,820 --> 00:03:54,971 These versions may have experimental features that aren't added for 49 00:03:54,971 --> 00:03:56,740 the long term. 50 00:03:56,740 --> 00:03:57,567 Because of this, 51 00:03:57,567 --> 00:04:01,050 you'll generally want to avoid using these versions in production code. 52 00:04:03,220 --> 00:04:08,019 To review, [SOUND] major changes are the most important to watch out for 53 00:04:08,019 --> 00:04:10,147 and may require refactoring. 54 00:04:10,147 --> 00:04:13,760 Minor changes typically won't affect your apps. 55 00:04:13,760 --> 00:04:15,645 Bug fixes are usually beneficial and 56 00:04:15,645 --> 00:04:18,150 shouldn't have any other effects on your apps. 57 00:04:19,420 --> 00:04:23,228 Knowing more about versioning we can better decide which package and 58 00:04:23,228 --> 00:04:26,200 version to include in our projects. 59 00:04:26,200 --> 00:04:30,706 In the upcoming videos, where we learn more about working with packages, 60 00:04:30,706 --> 00:04:35,580 we'll also learn how we can install or update to a specific version of a package. 61 00:04:36,790 --> 00:04:40,386 This will give you more control over exactly which code you're using 62 00:04:40,386 --> 00:04:41,130 in your apps.