0
0
Node.jsframework~5 mins

package-lock.json and deterministic installs in Node.js - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of package-lock.json in a Node.js project?

package-lock.json locks the exact versions of all installed packages and their dependencies. It ensures that everyone working on the project installs the same versions, making installs predictable and consistent.

Click to reveal answer
beginner
How does package-lock.json help with deterministic installs?

It records the full dependency tree with exact versions and sources. When you run npm install, npm uses this file to install the exact same versions every time, avoiding surprises from updated packages.

Click to reveal answer
beginner
True or False: package-lock.json should be committed to version control.

True. Committing package-lock.json ensures all team members and deployment environments use the same package versions, improving reliability.

Click to reveal answer
intermediate
What happens if package-lock.json is missing when running npm install?

npm will resolve package versions based on package.json rules and fetch the latest matching versions. This can lead to different versions installed on different machines, breaking deterministic installs.

Click to reveal answer
intermediate
Explain the difference between package.json and package-lock.json.

package.json lists the packages your project needs with version ranges (like ^1.2.0). package-lock.json records the exact versions installed, including nested dependencies, to ensure consistent installs.

Click to reveal answer
What file ensures that npm installs the exact same package versions every time?
Apackage.json
Bpackage-lock.json
C.npmrc
Dnode_modules
If package-lock.json is deleted, what is likely to happen on the next npm install?
Anpm installs exact same versions as before
Bnpm fails to install any packages
Cnpm installs latest matching versions based on <code>package.json</code>
Dnpm ignores <code>package.json</code>
Should package-lock.json be committed to git?
AYes, to ensure consistent installs
BNo, it should be ignored
COnly for production projects
DOnly if using yarn
Which file lists your project’s direct dependencies with version ranges?
Apackage.json
Bpackage-lock.json
Cnpm-shrinkwrap.json
Dnode_modules
What is the main benefit of deterministic installs?
AFaster internet speed
BAutomatic code formatting
CSmaller package sizes
DConsistent package versions across installs
Describe how package-lock.json helps maintain consistent package versions in a team project.
Think about how to avoid different versions on different machines.
You got /4 concepts.
    Explain the difference between package.json and package-lock.json and why both are important.
    One is a wish list, the other is a snapshot.
    You got /4 concepts.