Back to Freecodecamp

Use the Caret-Character to Use the Latest Minor Version of a Dependency

curriculum/challenges/english/blocks/managing-packages-with-npm/587d7fb5367417b2b2512c03.md

latest1.7 KB
Original Source

--description--

Similar to how the tilde we learned about in the last challenge allows npm to install the latest PATCH for a dependency, the caret (^) allows npm to install future updates as well. The difference is that the caret will allow both MINOR updates and PATCHes.

Your current version of @freecodecamp/example should be ~1.2.13 which allows npm to install to the latest 1.2.x version. If you were to use the caret (^) as a version prefix instead, npm would be allowed to update to any 1.x.x version.

json
"package": "^1.3.8"

This would allow updates to any 1.x.x version of the package.

--instructions--

Use the caret (^) to prefix the version of @freecodecamp/example in your dependencies and allow npm to update it to any new MINOR release.

Note: The version numbers themselves should not be changed.

--hints--

"dependencies" should include "@freecodecamp/example".

js
fetch(code + '/_api/package.json')
  .then(response => response.json())
  .then(
    data => {
      assert.property(
        data.dependencies,
        '@freecodecamp/example',
        '"dependencies" does not include "@freecodecamp/example"'
      );
    },
    error => {
      throw new Error(error.message || error.responseText);
    }
  );

"@freecodecamp/example" version should match "^1.x.x".

js
fetch(code + '/_api/package.json')
  .then(response => response.json())
  .then(
    data => {
      assert.match(
        data.dependencies['@freecodecamp/example'],
        /^\^1\./,
        'Wrong version of "@freecodecamp/example". It should be ^1.2.13'
      );
    },
    error => {
      throw new Error(error.message || error.responseText);
    }
  );