我意识到,当我进行node.js模块的全局安装(带有-g标志)时,除非我编写了整个路径,否则节点无法使用该模块.
我的意思是,如果模块已全局安装,这不起作用:
cheerio = require('cheerio'),
我必须写下:
cheerio = require('/usr/lib/node_modules/cheerio'),
我怎么能对节点说它必须在正确的路径中寻找模块?
谢谢.
ink*_*nki 50
一般来说,我建议让npm给你路径并设置如上所述:
$ echo 'export NODE_PATH="'$(npm root -g)'"' >> ~/.bash_profile && . ~/.bash_profile
Vik*_*ari 16
对于Windows平台上的用户,在系统变量中将其添加到PATH中:
C:\Users\<username>\AppData\Roaming\npm
PS:在Windows 8.1上测试过
Err*_*ald 15
您可以将以下内容添加到〜/ .bash_profile:
export NODE_PATH=/usr/lib/node_modules:$NODE_PATH
| 归档时间: | 
 | 
| 查看次数: | 84635 次 | 
| 最近记录: |