用forever作为Nodejs的守护进程启动,linux有报错,求解释

用forever作为Nodejs的守护进程启动,linux有报错,求解释

error: Could not read .foreverignore file. error: ENOENT, open '/.foreverignore’ Failed to load c++ bson extension, using pure JS version js-bson: Failed to load c++ bson extension, using pure JS version

Error: Most middleware (like compress) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware. at Function.Object.defineProperty.get (/opt/node/mptool/node_modules/express/lib/express.js:89:13) at Object.<anonymous> (/opt/node/mptool/app.js:39:17) 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 Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:906:3

error: Forever detected script exited with code: 8 error: Script restart attempt #1

/usr/lib/node_modules/forever/node_modules/forever-monitor/node_modules/watch/main.js:73 if (err) throw err; ^ Error: ENOENT, stat ‘/proc/25442/cwd/bin’


5 回复

问题描述

在使用 forever 作为 Node.js 的守护进程启动时,在 Linux 系统上遇到了一些错误。错误信息包括文件读取失败、缺少 C++ 扩展以及脚本重启尝试等。

错误分析

  1. .foreverignore 文件读取错误

    error: Could not read .foreverignore file.
    error: ENOENT, open '/.foreverignore'
    

    这个错误提示 .foreverignore 文件无法被读取。可能是因为该文件不存在或者路径不正确。确保 .foreverignore 文件存在并且路径正确。

  2. C++ 扩展加载错误

    Failed to load c++ bson extension, using pure JS version
    js-bson: Failed to load c++ bson extension, using pure JS version
    

    这通常是因为缺少某些依赖项或编译环境配置不正确。确保安装了所有必要的依赖项,并且编译环境已正确配置。

  3. Express 中间件错误

    Most middleware (like compress) is no longer bundled with Express and must be installed separately.
    

    这个错误提示 Express 中间件不再包含在 Express 中,需要单独安装。可以尝试运行以下命令来安装缺失的中间件:

    npm install express-compress
    
  4. Forever 脚本重启错误

    error: Forever detected script exited with code: 8
    error: Script restart attempt #1
    

    这个错误提示脚本由于某种原因退出,并且 forever 尝试重新启动它。检查脚本是否有异常退出的原因。

  5. 文件路径错误

    Error: ENOENT, stat '/proc/25442/cwd/bin'
    

    这个错误提示找不到指定路径的文件。确保路径正确,并且文件存在。

示例代码与解决方案

  1. 检查 .foreverignore 文件

    • 确保 .foreverignore 文件存在且路径正确。
    • 如果不需要 .foreverignore 文件,可以删除或注释掉相关代码。
  2. 安装缺失的依赖项

    • 确保安装了所有必要的依赖项:
      npm install
      
  3. 安装缺失的中间件

    • 安装缺失的中间件:
      npm install express-compress
      
  4. 检查脚本错误

    • 检查脚本中是否有异常退出的原因,例如:
      try {
        // 你的代码
      } catch (err) {
        console.error(err);
        process.exit(1); // 异常退出
      }
      

通过以上步骤,应该能够解决大部分错误并成功启动 Node.js 应用程序。如果还有其他问题,请提供更多的错误日志以便进一步排查。


没有回答的吗

这个应该是程序的问题吧,和forever没有关系吧,Error: Most middleware (like compress) is no longer bundled with Express and must be installed separately

forever给node打了一个响亮的耳光

根据你描述的错误信息,这些问题可能是由多个不同的原因导致的。下面分别对每个错误进行简要解释并提供可能的解决方案。

错误1: .foreverignore 文件读取错误

error: Could not read .foreverignore file.
error: ENOENT, open '/.foreverignore’

解释ENOENT 表示 “No such file or directory”,这通常是因为指定的文件或目录不存在。 解决方案:

  1. 确认 .foreverignore 文件是否存在。如果不需要使用此文件,可以删除相关的配置或创建一个空的 .foreverignore 文件。
  2. 检查文件路径是否正确。

错误2: js-bson 扩展加载失败

Failed to load c++ bson extension, using pure JS version
js-bson: Failed to load c++ bson extension, using pure JS version

解释: 这通常是由于缺少编译好的 C++ 扩展库导致的。这可能会增加一些性能开销,但不影响程序运行。 解决方案: 尝试重新安装 bson 库,确保安装了正确的版本:

npm install bson

错误3: Express 中间件问题

Most middleware (like compress) is no longer bundled with Express and must be installed separately.

解释: Express 从某些版本开始不再捆绑某些中间件,需要单独安装这些中间件。 解决方案: 安装你需要的中间件,例如压缩中间件:

npm install compression

并在你的代码中引入:

const compression = require('compression');
app.use(compression());

错误4: Forever 监控脚本重启

error: Forever detected script exited with code: 8
error: Script restart attempt #1

解释: 这表明你的 Node.js 脚本在运行时遇到了某种错误导致退出,Forever 尝试自动重启它。 解决方案: 检查你的应用程序日志,找到退出时的具体错误信息。在上面的错误信息中,错误可能发生在 main.js 文件的第 73 行。

错误5: stat 命令错误

Error: ENOENT, stat ‘/proc/25442/cwd/bin’

解释: 这通常表示系统在尝试访问某个不存在的路径时发生错误。 解决方案: 确保你的脚本没有引用不存在的路径,并且检查是否有环境变量或配置文件中设置了不正确的路径。

希望上述解释和解决方案能够帮助你解决问题。如果还有其他疑问,建议查看具体的错误堆栈信息以获得更详细的线索。

回到顶部