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
- Install it in both places. Seriously, are you that short on disk space? It’s fine, really. They’re tiny JavaScript programs.
- 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.)