Npm install: use the global package if it exists, instead of installing twice

When using npm install with the package.json file, how can I get it to use a globally installed package that meets the criteria, rather than downloading and installing the package locally again?

I know about link , but is there a way to do what I am describing?

+8
source share
1 answer

One way to do this for a specific set of modules is to remove these modules from the dependencies section and create a prestart script containing all the modules that you prefer to install around the world.

A simple example might look something like this:

  "scripts": { "test": "mocha", "prestart": "npm i -g mocha mysql bluebird" }, 

Instead of prestart you can use one of the other hooks, such as preinstall and prepare . Please note that this will not work with the packages you want to publish, and will require a bit more hacking.

Help when running scripts: https://docs.npmjs.com/misc/scripts

0
source

All Articles