Lesson 6.4Lesson 23 of 24
npm package management
Given a scenario and requirements, distinguish which Node.Js Package Management solution is the most fitting.
Key points
- 1dependencies are needed at run time; devDependencies only for building and testing (npm install -D); peerDependencies name a host package shared with the app; npm 7+ installs it.
- 2Caret ^1.4.2 allows any 1.x.y from 1.4.2 up; tilde ~1.4.2 allows only 1.4.x. For 0.x versions, ^0.3.1 stays below 0.4.0.
- 3package-
lock.jsonrecords the exact version of every installed package. Commit it, so everyone gets the same tree. - 4npm ci installs exactly what the lock file says and fails if it disagrees with
package.json; npm update moves packages within their ranges and records the new versions in the lock file, not inpackage.json. - 5npm run name runs a script with
node_modules/.bin on the PATH; npx runs a package's command without a global install.
What the exam guide checks here
Objective wording from the exam guide (English).
- 6.4.K1npm: package.json, dependencies vs devDependencies, scripts, package-lock.json
- 6.4.K2Semantic versioning ranges (^, ~), npm install vs npm ci, npx
- 6.4.S1Choose the package management command or setting that meets a requirement
Lock it in
Answer scenario questions on this topic. Every option comes with an explanation.
Practise 6.4 · 12 questions