node.js模块路径
我意识到,当我进行node.js模块的全局安装(带有-g标志)时,除非我编写了整个路径,否则节点无法使用该模块。
我的意思是,如果模块已全局安装,这不起作用:
cheerio = require('cheerio'),
我必须写下:
cheerio = require('/usr/lib/node_modules/cheerio'),
我怎么能对节点说它必须在正确的路径中寻找模块?
谢谢。
回答如下:一般来说,我建议让npm给你路径并设置如上所述:
$ echo 'export NODE_PATH="'$(npm root -g)'"' >> ~/.bash_profile && . ~/.bash_profile
node.js模块路径
我意识到,当我进行node.js模块的全局安装(带有-g标志)时,除非我编写了整个路径,否则节点无法使用该模块。
我的意思是,如果模块已全局安装,这不起作用:
cheerio = require('cheerio'),
我必须写下:
cheerio = require('/usr/lib/node_modules/cheerio'),
我怎么能对节点说它必须在正确的路径中寻找模块?
谢谢。
回答如下:一般来说,我建议让npm给你路径并设置如上所述:
$ echo 'export NODE_PATH="'$(npm root -g)'"' >> ~/.bash_profile && . ~/.bash_profile