13

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

Inzamam Malik
  • 3,238
  • 3
  • 29
  • 61

2 Answers2

9

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.

RyanZim
  • 6,609
  • 1
  • 27
  • 43
  • are you sure that after doing this, `npm install` will not make `node_modules` folder in my project but install all dependencies in a pool? – Inzamam Malik Mar 14 '17 at 13:29
  • 1
    `npm install` will always make a `node_modules` folder in your project. There is no way to get around that, due to the way Node.js works. The `link` option will just make the `node_modules` folder smaller in size (it will contain mostly symlinks). – RyanZim Mar 14 '17 at 14:07
1

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

Abdul.Moqueet
  • 902
  • 12
  • 19