1

why it is necessary to ignore node_modules from git repo?

The other users who will use my code from repo ,don't they will need my node_modules folder ?

  • 1
    node_modules contains "code from other repositories" that can easily be obtained from those repositories and your packages.json file will already make it so they get the exact versions they need from their original repositories. There is no advantage and lots of disadvantage to you making a whole new repository for each of the node modules that you are using in your project. Further the actual repositories for all those modules contain their history, their issues database, their documentation, etc... – jfriend00 Feb 25 '18 at 17:44
  • https://stackoverflow.com/questions/11459475/should-i-check-in-node-modules-to-git-when-creating-a-node-js-app-on-heroku https://stackoverflow.com/questions/17069782/gitignore-and-node-modules https://stackoverflow.com/questions/19328613/why-is-the-node-modules-folder-not-committed-to-git – Josh Lee Feb 25 '18 at 17:56

3 Answers3

0

These modules are external dependencies of your application and you should have added them in your packages.json accordingly.

You don't have to include the entire source of these packages because you can install them with a single command: npm install, and for many other reasons (see jfriend00 comment).

So usually, when developping an app, we add node_modules to .gitignore to prevent dependencies from being versionned.

It is not necessary (you can always do what you want), but it is strongly recommanded to leave your repo clean and maintainable.

TGrif
  • 5,725
  • 9
  • 31
  • 52
0

node_module is too big and you already have package.json that helps to to install all packages in node_module by npm install / yarn install command.

keep small, clean and maintainable so add node_module in .gitignore file .

Man
  • 742
  • 1
  • 6
  • 23
0

There is no need to version the whole node_modules, because you achieve the same goal using the package.json file, which is the description of the dependencies required by your application.

When other users check-in your versionned code, a simple npm install is enough to gather those dependencies using the description provided in the package.json file.

Cf. Why is the node_modules folder not committed to Git?

N. Labrahmi
  • 657
  • 4
  • 23