A generated npm lockfile records the exact dependency tree, complementing package.json, which can specify version ranges. When someone runs npm install, npm uses the lockfile to recreate that tree. section 3.2.3 section 3.4
Commit package-lock.json to version control, but leave node_modules out. This lets teammates reproduce dependencies without committing the downloaded packages; if a lockfile merge conflict occurs, running npm install can resolve it. section 3.2.3
"dependencies": {
"express": "^5.1.0"
}
A package.json dependency can use a caret range, while the lockfile records the exact resolved versions. section 3.2.3
Whether to commit a lockfile for a package consumed by others is debated: it freezes versions during development, but does not control the dependency tree of downstream projects. section 3.2.3
