Reputation: 774
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. :)
Upvotes: 35
Views: 37287
Reputation: 10808
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 <dependencyName>
or npm install --save-dev <dependencyName>
. 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.
Upvotes: 47
Reputation: 1508
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.
Upvotes: 2