NodeJS需要一个全局模块/包 [英] NodeJS require a global module/package

查看:157
本文介绍了NodeJS需要一个全局模块/包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试全局安装,然后像这样使用foreverforever-monitor:

I'm trying to install globally and then use forever and forever-monitor like this:

npm install -g forever forever-monitor

我看到了通常的输出以及将文件复制到全局路径的操作,但是如果我尝试require("forever");,则会收到一条错误消息,指出未找到该模块.

I see the usual output and also the operations that copy the files to the global path, but then if I try to require("forever"); I get an error saying that the module wasn't found.

我正在使用node和npm的最新版本,并且我已经知道npm在全局安装与本地安装中所做的更改,但是我真的不想在每个项目上都安装localy而且我正在一个不支持link的平台上工作,所以对我来说全局安装后npm link是不可能的.

I'm using latest version of both node and npm and I already know about the change that npm made in global vs local install, but I really don't want to install localy on every project and I'm working on a platform that doesn't support link so npm link after a global install isn't possible for me.

我的问题是:为什么我不需要全局安装的软件包?那是功能还是错误?还是我做错了什么?

My question is: why I can't require a globally installed package? Is that a feature or a bug? Or am I doing something wrong?

PS:明确地说:我不想在本地安装.

PS: Just to make it crystal clear: I don't want to install locally.

推荐答案

在Node.js中,require不会在安装全局模块的文件夹中查找.

In Node.js, require doesn't look in the folder where global modules are installed.

您可以通过设置NODE_PATH环境变量来解决此问题.在Linux中,它将是:

You can fix this by setting the NODE_PATH environment variable. In Linux this will be:

export NODE_PATH=/usr/lib/node_modules

注意:这取决于您的全局模块的实际安装位​​置.

请参阅:从全局文件夹中加载.

这篇关于NodeJS需要一个全局模块/包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆