Skip to content

Instantly share code, notes, and snippets.

@ngohuytrieu
Last active December 6, 2021 10:11
Show Gist options
  • Save ngohuytrieu/3177495e9c10b69388bfde9c1bdf2027 to your computer and use it in GitHub Desktop.
Save ngohuytrieu/3177495e9c10b69388bfde9c1bdf2027 to your computer and use it in GitHub Desktop.
package.json vs package-lock.json

Different

  • package.json: list of module needs for project
  • package-lock.json: same idea but with lock specific version that already works when run npm i from package.json

Why do we need package-lock.json

  • Semantic Versioning (semver) has structure like: ^MAJOR.MINOR.PATCH
  • With ^ when run npm i it will install newest version of the same MAJOR. But with the newest MINOR or PATCH (install on new pc) could cause some issue or bug
  • The package-lock.json solves this by defining the MAJOR.MINOR.PATCH preciously that works.

Install

  • package.json: npm i
  • package-lock.json: npm ci
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment