npm, package.json and Dependencies — Concept Check
Questions on npm, package.json and Dependencies. package.json is the manifest and the lockfile is the truth. Understanding semver ranges and why the lockfile is committed prevents the "works on my machine" class of bug.
Questions in this quiz
7 questions on npm, package.json and Dependencies — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer installs dependencies using `npm install` and later commits the lockfile. What is the main benefit of this practice?
- AReduces the size of the node_modules folder
- BAutomatically updates all dependencies to the latest versions
- CEnsures reproducible builds across environments
- DPrevents any changes to package.json
2.A package.json specifies "zod": "^3.23.0". What version might a teammate install if they run `npm install` a month later?
- A4.0.0
- B3.24.5
- C3.23.1
- D3.22.0
3.What happens if a developer skips committing the lockfile and another developer installs dependencies?
- AThey will have an identical setup
- BThey might end up with different versions of dependencies
- CThe lockfile will be automatically generated
- DThe installation will fail
4.A developer wants to ensure only patch updates for a dependency. Which version range should they use?
- A1.x
- B1.2.3
- C^1.2.3
- D~1.2.3
5.A developer sees `npm ci` used in a CI pipeline. What is the primary reason for this?
- ATo update all dependencies to their latest versions
- BTo generate a new lockfile
- CTo skip the installation of devDependencies
- DTo install exactly what's in the lockfile
6.Which command should be used to check for outdated dependencies without updating them?
- Anpm update
- Bnpm audit
- Cnpm outdated
- Dnpm install
7.A developer adds a new dependency without checking its transitive dependencies. What risk does this pose?
- AIt reduces the project's bundle size
- BIt ensures compatibility with all existing packages
- CIt might introduce unnecessary maintenance overhead
- DIt will automatically optimize the build process