Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

doing npm install for each project takes too much space in drive

Tags:

node.js

npm

is there any way to route npm install to a specific part of hard drive and when i do npm install it make node_module folder in that part of drive, and when i run any project it look for dependencies in that part of drive, just like single pool for every project.

then if i have two projects with similar dependencies then i only need to npm install in one project so dependencies become available in pool, and no need to do npm install in another project just npm start

Thank you, Inzamam Malik

like image 856
Inzamam Malik Avatar asked Mar 14 '17 09:03

Inzamam Malik


People also ask

How much space does npm install take?

Please reserve at least 6 GB for OS resources and npm On-Site appliance containers.

Do I need to run npm install for every project?

It is not necessary to do "npm install" each time you want to compile. You just need to do it when you change the dependencies of your project.

Why npm install taking too much time?

If you find that npm is running slow and it isn't your computer or internet, it is most likely because of a severely outdated version.


2 Answers

You can achieve something close to what you are describing with the link option.

From https://docs.npmjs.com/misc/config#link:

If true, then local installs will link if there is a suitable globally installed package.

Note that this means that local installs can cause things to be installed into the global space at the same time. The link is only done if one of the two conditions are met:

  • The package is not already installed globally, or
  • the globally installed version is identical to the version that is being installed locally.

So you will still have some files in each project's node_modules, but you shouldn't have as large a folder.

To turn this behavior on, run:

npm config set link -g

Edit: There is no way you can avoid running npm install and having a node_modules folder. Node.js always looks in node_modules for dependencies (this behavior pre-dates npm itself). The link option will make npm create symlinks in node_modules, pointing to a common pool. That will reduce disc usage, but you cannot do away with node_modules.

like image 120
RyanZim Avatar answered Sep 18 '22 14:09

RyanZim


You can use PNPM Package manager, It uses a global pool for dependencies.

like image 38
Abdul.Moqueet Avatar answered Sep 19 '22 14:09

Abdul.Moqueet