Search code examples
npmdependenciesrepositorygit-commitpackage.json

Should changes in a package.json file be commited to a repository as well?


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. :)


Solution

  • 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.