Should I install all the npm packages when making a new project?

Viewed 456

A just started getting familiar with npm packages and node. When installing packages they create a lot of folders in the "node modules" and i wonder if when i'll create a completely new project should i install all these packages again while having them already installed in previous projects? Or i just need to link the new projects with these packages with the package.json file?

3 Answers

You definitely shouldn't install all the packages - just those that you need.

While there are some ways to save space in node_modules, but unless it's an exceptional situation, I wouldn't start with them. It's much simpler to manage dependencies for every project independently, and it would save you a world of trouble if every project own its own dependencies and can upgrade/downgrade/replace them if needed.

If you want to keep your project portable or make them usable for others, I you should just redownload the modules. If you link a folder on your PC and then send the code to someone else, they will not be able to execute it. BTW if you want to publish your code on Github (or something similar) then you can add node_modules to .gitignore .

It always depends on what you're wanting to build. If you know exactly which packages you need to install, then you can install all of them beforehand. But, most of the time, only "npm install" something when needed. Don't forget to add node_modules to .gitignore file too.

Related