node.js - npm如何将模块安装到全局?
阿神
阿神 2017-04-17 11:06:53
0
2
826

npm -g install eventproxy表示用全局模式安装包,但是不代表你可以在任何地方require到这个包,在Linux下它其实把包安装到/usr/local/lib/node_modules下,然后通过软连接的方式把包中bin目录下的可执行文件链接到/usr/local/bin下面(和node一个目录)。

但是我希望能够在任何地方都能够require这个包。
我的做法是修改/etc/profile
在文件尾加上一行export NODEPATH="NODEPATH:/usr/local/lib/node_modules"
然后source /etc/profile

可这依然达不到我要的效果,请问应该怎么做才能把包安装到全局?

阿神
阿神

闭关修行中......

reply all(2)
阿神

If you need require a global package, you can npm link go to local first.

The philosophy of npm is that each project manages its own modules to avoid the trouble caused by the dependencies of each project being mixed together.

If you just find it troublesome to fiddle with dependencies every time you start a project, you can try autod

黄舟

No matter which folder you are in, execute npm link xxx . If there is no xxx module, then xxx will be installed globally first, and then linked from the global

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template