Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between package.json, package-lock.json and yarn.lock files?

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

like image 824
Vaibhav Avatar asked Jul 06 '18 05:07

Vaibhav


1 Answers

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.

like image 151
Matthew Mullin Avatar answered Sep 30 '22 09:09

Matthew Mullin