package-lock.json
Definition
An automatically generated file that describes the exact dependency tree that was installed, ensuring that subsequent installs reproduce an identical node_modules tree.
Explain Like I'm New
If package.json is the recipe, package-lock.json is the exact grocery store receipt. It says: 'You installed Express version 4.18.2 on Tuesday, and Express requires Accepts version 1.3.8'. It locks down the exact sub-versions of every single library so that if another developer runs `npm install`, they get the exact same code, avoiding 'It works on my machine' bugs.
Real World Example
You deploy your app on Friday. It works. Over the weekend, a deeply nested library (`is-regex`) pushes a broken update. Without a package-lock, your server might download the broken update on Monday and crash. The lockfile prevents this.
Common Use Cases
- •Consistent environments
- •Deterministic deployments
- •Security auditing
Interactive Example
Interview Questions
basic
- Should you commit `package-lock.json` to Git/GitHub?
intermediate
- What is the difference between `npm install` and `npm ci`?