首页 > npm 全局安装和本地安装的区别究竟是什么?

npm 全局安装和本地安装的区别究竟是什么?

除了调用方式,安装位置外,我还想问以下问题。


全局安装

全局安装-g 就是只安装一次就行了,一般像工具类的比如 bower 我都会全局安装, 一般会安装在 /usr/local 或者你 node 安装的目录。

一般安装在全局的都是有命令行需求的 package,比如前边说的 bower,你需要在命令行中使用 bower 这个命令。

本地

项目中的库都不会全局安装,npm install 时安装在 ./node_modules 里,简单说就是安装位置不一样

这些库你只需要 require() 就能用了。

npm link

npm link 这个你可以看下

First, npm link in a package folder will create a globally-installed symbolic link from prefix/package-name to the current folder (see npm-config(7) for the value of prefix).

link:

https://docs.npmjs.com/cli/install
https://docs.npmjs.com/cli/link

【热门文章】
【热门文章】