I have understood the details from the below link but still when to use which file is a question ?
https://docs.npmjs.com/files/package-lock.json
Asked
Active
Viewed 3,958 times
6
1 Answers
10
package.json
Contains relevant metadata for your project including dependancies, helper scripts and other general metadata.
Running npm install --save <package>
or yarn add <package>
adds dependancies to this file.
Between the three files listed, this is the only one you should ever need to interact with.
package-lock.json and yarn.lock
Is an auto generated file that describes the exact state of your application dependancies the last time packages where added or modified.
More specifically it guarantees the order of package installations between users - hence why it is recommended to be git committed.
yarn.lock is generated when running yarn
specific commands.
package-lock.json is generated when running npm
specific commands.

Matthew Mullin
- 7,116
- 4
- 21
- 35
-
Thank you so much for this explanation – Boingoloid Jun 19 '23 at 18:26