How caret, tilde and exact ranges decide
This is a small copy of the rules in the real semver package that npm uses. The real one also handles ranges like >=1.2 <2, 1.x, ||, and pre-release versions such as 2.0.0-beta.1.
npm is the package manager that comes with Node.js: package.json lists your project's name, scripts and the packages it depends on (with version ranges), node_modules holds the installed code, and the lockfile pins the exact versions so every install is identical.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write a function bumpType(oldVersion, newVersion) that returns "major", "minor", "patch" or "same".
Write the package.json scripts for a project that runs Vite in development, builds with vite build, lints with eslint . and runs the linter automatically before every build.
For each change, say which version number you bump: (a) fix a rounding bug; (b) add a new optional currency option; (c) rename the function format to formatPrice.
Explain it without notes
What is the difference between dependencies and devDependencies?
Explain semver and what ^, ~ and an exact version mean in package.json.
Why should you commit package-lock.json, and when do you use npm ci instead of npm install?
How do npm scripts find tools like vite and eslint?
Preview
Console
Nothing logged yet.Expected console output
^4.17.21 allows 4.18.0 true
^4.17.21 allows 5.0.0 false
~4.17.21 allows 4.17.30 true
~4.17.21 allows 4.18.0 false
^0.3.1 allows 0.3.9 true
^0.3.1 allows 0.4.0 false
4.17.21 allows 4.17.22 false