1

I have multiple Angular 2 projects and each of them contains package.json file. I run npm install command on those files to install node modules for each of those project. Since each project has a node_modules folder now, I'd like to have just one node_modules folder shared among all projects and install additional modules to that folder.

I tried running npm install --prefix .. command in first project. Here's the result:

-my_projects
--project1
---package.json
--project2
---package.json
--project3
---package.json
--node_modules
---project1
----node_modules
----all_other_project_files_and_folders
--etc

What happened? Yes, node_modules folder in a parent folder was created as I expected, but in that folder, a copy of my entire project is also included. I just wanted to install all of my project's dependencies in one common folder instead of duplicating those modules' installations in multiple projects.

How can I achieve this? Is a '--prefix' option the right way at all?

peterremec
  • 488
  • 1
  • 15
  • 46

1 Answers1

0

This similar question might help you out: npm local install package to custom location

Although I would suggest just installing globally using the -g or --global flags if your goal is to have npm packages available to all (current and future) projects.

Example: sudo npm install express -g

Community
  • 1
  • 1
Federico Pettinella
  • 1,471
  • 1
  • 11
  • 19