I am not sure that if it is correct to commit and push the changes in the package.JSON file into a repository. as far as I understood, the others in the git can install new dependencies by executing this command: npm install and accordingly, their package.JSON will be updated too.OR, this files actually says what are the new dependencies and needs to be pushed as well. It would be great if some could clarify me. :)
json file needs to be committed to your Git repository, so it can be fetched by other people, if the project is public or you have collaborators, or if you use Git as a source for deployments. The dependencies versions will be updated in the package-lock.
The repository property of a package. json is an array that defines where the source code for the module lives. Typically, this would be a public GitHub repo for open source projects, with the repository array noting that the type of version control is git and the URL of the repo itself.
package-lock. json is updated automatically on dependency changes. It should be committed to version control to ensure the same dependencies on install.
You need to commit package.json
. All other developers, after pulling the code, will just need to perform npm install
to get the latest dependencies required for the project.
Whenever you or someone else wants to add new dependencies to the project you perform npm install --save
or npm install --save-dev
. Then package.json
is automatically updated, and needs to be committed again.
Note: dependencies should not be committed, so you need to add node_modules
to the .gitignore
file (supposing you use git), and commit this file also.
It depends, are the packages that were added to the package.json
file required for the application to run?
If not, then no. For packages that are not required to run then use the following command:
npm install {package} --saveDev
This saves the package to the package.json
file as a development package and not something that is required to run the app.
You dont have to commit changes unless they are necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With