Installing one npm package can download many. A dependency tree represents a project’s direct dependencies and the packages those dependencies require, recursively. For example, installing Express makes npm fetch Express and its dependencies until the tree is complete; the downloaded packages appear in node_modules. section 3.2.1
One request, a full tree
Run npm install express@5. package.json records Express as a top-level dependency, while package-lock.json records the full installed tree. Importing Express in an .mjs file then lets a Node.js application use it. section 3.2.1
The two files serve different purposes. package.json can allow a version range, such as ^5.1.0; package-lock.json specifies exact versions throughout the tree. Commit the lockfile rather than node_modules so npm install can reconstruct the same installed tree on another machine. A lockfile in a package consumed by other projects does not, however, force those projects to use its local dependency tree. section 3.2.3
Do not confuse the installed package tree with an import dependency tree. A module waits until its static imports—and their imports—have loaded before it executes. The first tree concerns installed packages; the second concerns modules needed for execution. section 3.4 section 13.1.2
