最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

node.js模块路径

IT培训 admin 6浏览 0评论

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

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论