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
可这依然达不到我要的效果,请问应该怎么做才能把包安装到全局?
If you need
require
a global package, you cannpm 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