Node.js 在多个项目上使用永久节点模块

Node.js 在多个项目上使用永久节点模块,node.js,mongodb,ubuntu,forever,Node.js,Mongodb,Ubuntu,Forever,我正在服务器上设置两个不同的web应用程序项目。我正在尝试正确设置Node、MongoDB和Forever节点模块,以便我可以在脚本中使用Forever来保持它们全天候运行 我遇到的主要问题是节点和两个模块的本地与全局安装。现在,我已经使用一些在线资源以及我在这里找到的bash脚本()尝试了五次安装过程 我所做的一切似乎都不正常。要么Forever命令在我的应用程序文件夹中不起作用,要么Forever起作用时,进程会立即停止,并创建一个日志文件。以下是日志文件的内容: module.js:340

我正在服务器上设置两个不同的web应用程序项目。我正在尝试正确设置Node、MongoDB和Forever节点模块,以便我可以在脚本中使用Forever来保持它们全天候运行

我遇到的主要问题是节点和两个模块的本地与全局安装。现在,我已经使用一些在线资源以及我在这里找到的bash脚本()尝试了五次安装过程

我所做的一切似乎都不正常。要么Forever命令在我的应用程序文件夹中不起作用,要么Forever起作用时,进程会立即停止,并创建一个日志文件。以下是日志文件的内容:

module.js:340
    throw err;
      ^
Error: Cannot find module 'mongodb'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/var/www/html/test/requestHandlers.js:6:13)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
error: Forever detected script exited with code: 8
永久创建的最新错误日志:

/var/www/html/test/node_modules/mongodb/lib/mongodb/db.js:403
  if(connection && connection.serverCapabilities.hasListCollectionsCommand) {
                                            ^
TypeError: Cannot read property 'hasListCollectionsCommand' of undefined
    at Db.listCollections (/var/www/html/test/node_modules/mongodb/lib/mongodb/db.js:403:49)
    at Db.createCollection (/var/www/html/test/node_modules/mongodb/lib/mongodb/db.js:1026:8)
    at Object.<anonymous> (/var/www/html/test/requestHandlers.js:15:4)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
at Object.<anonymous> (/var/www/html/test/indextest.js:3:23)
error: Forever detected script exited with code: 8
/var/www/html/test/node_modules/mongodb/lib/mongodb/db.js:403
if(connection&&connection.serverCapabilities.hasListCollectionsCommand){
^
TypeError:无法读取未定义的属性“hasListCollectionsCommand”
在Db.listCollections(/var/www/html/test/node_modules/mongodb/lib/mongodb/Db.js:403:49)
位于Db.createCollection(/var/www/html/test/node_modules/mongodb/lib/mongodb/Db.js:1026:8)
在对象上。(/var/www/html/test/requestHandlers.js:15:4)
在模块处编译(Module.js:456:26)
在Object.Module.\u extensions..js(Module.js:474:10)
在Module.load(Module.js:356:32)
在Function.Module.\u加载(Module.js:312:12)
at Module.require(Module.js:364:17)
根据需要(模块js:380:17)
at对象。(/var/www/html/test/indextest.js:3:23)
错误:检测到脚本已退出,代码:8

这与您链接到的脚本没有任何关系,也不会永远存在。您能展示一下如何使用
require()
?我绝对不会全局安装模块。Forever可以全局安装,因为它不是您在应用程序中使用的东西。另外,为了说明它的价值,下面是我如何安装Node.js:
curl-shttp://nodejs.org/dist/latest/node-v0.10.35-linux-x64.tar.gz |tar xzf---strip components=1--directory/usr/local
然后,永久安装:
npm install-g Forever
如果你不想弄乱PPA,这就简单了。#第一条评论-不确定你指的是什么。我在大学里被教过如何以某种方式进行安装,这一切都可以在另一台服务器上正常工作。我最终不得不将项目转移到一个新的服务器上,而不是在另一台服务器上重新移植所有内容后,我决定用最新版本重新开始。第二条评论-安装MongoDB怎么样?它会和永远一样吗?好吧,我们不知道你在大学里学到了什么。坦率地说,我在大学里看到过很多不好的做法。如果你在全球范围内安装MongoDB NPM模块,那么这通常是一个糟糕的做法。您应该做的是
npm安装--保存
,以便用您的模块列表更新您的package.json文件。然后,当您在其他地方安装应用程序时,一个简单的
npm安装
将安装所有依赖项。请向我们展示您的
require()
代码。
/var/www/html/test/node_modules/mongodb/lib/mongodb/db.js:403
  if(connection && connection.serverCapabilities.hasListCollectionsCommand) {
                                            ^
TypeError: Cannot read property 'hasListCollectionsCommand' of undefined
    at Db.listCollections (/var/www/html/test/node_modules/mongodb/lib/mongodb/db.js:403:49)
    at Db.createCollection (/var/www/html/test/node_modules/mongodb/lib/mongodb/db.js:1026:8)
    at Object.<anonymous> (/var/www/html/test/requestHandlers.js:15:4)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
at Object.<anonymous> (/var/www/html/test/indextest.js:3:23)
error: Forever detected script exited with code: 8