copy npm global installed package to local

2020-06-25 04:34发布

问题:

If I have a npm package installed globally, and I want to install the same package locally in some project, does npm download the package again or copy it from the global install folder? If not, is there a way to make it do that?

回答1:

It is not recommended to copy files from global to local. It is pretty normal to have package installed in both places.

  • Global package in most of the cases is used in terminal.
  • Local package is used in application itself.

Also you can use npm link to symlink a global package

  1. Install it in both places. Seriously, are you that short on disk space? It’s fine, really. They’re tiny JavaScript programs.
  2. Install it globally, and then npm link coffee-script or npm link express (if you’re on a platform that supports symbolic links.) Then you only need to update the global copy to update all the symlinks as well.

The first option is the best in my opinion. Simple, clear, explicit. The second is really handy if you are going to re-use the same library in a bunch of different projects. (More on npm link in a future installment.)



标签: node.js npm