node.js 模块路径 [英] node.js modules path
本文介绍了node.js 模块路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我意识到,当我对 node.js 模块(带有 -g 标志)进行全局安装时,除非我写了整个路径,否则节点无法使用该模块.
I realised that when I did a global installation of a node.js module (with the -g flag) node couldn't use that module unless I wrote the entire path.
我的意思是,如果模块已全局安装,这将不起作用:
I mean, this doesn't work if the module has been globally installed:
cheerio = require('cheerio'),
我必须这样写:
cheerio = require('/usr/lib/node_modules/cheerio'),
我怎么能告诉节点它必须在正确的路径中寻找模块?
How can I say to node that it has to look for the modules in the right path?
谢谢.
推荐答案
一般来说,我建议让 npm 为您提供路径并按上述方式设置:
In general, I would suggest letting npm give you the path and set that as mentioned above:
$ echo 'export NODE_PATH="'$(npm root -g)'"' >> ~/.bash_profile && . ~/.bash_profile
这篇关于node.js 模块路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文