生产中的节点群集错误

时间:2018-08-29 16:27:27

标签: javascript node.js express heroku

在生产环境中使用集群时,特别是调用fork()函数时,无论在本地还是在Heroku上,我都会收到此错误。我为WEB_CONCURRENCY = 1设置了一个变量。当我从server.js中删除集群时,它工作正常。

// server.js

let WORKERS = process.env.WEB_CONCURRENCY || 1;
let cluster = require('cluster');

if (cluster.isMaster) {
  for (let i = 0; i < WORKERS; i += 1) {
    cluster.fork();
  }
  cluster.on('exit', function(worker) {
    console.log(`worker ${worker.id} exit`);
    cluster.fork();
  });
}
else { ... setup Express }

//

Error: Cannot find module '/app/server/undefined'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
worker 150 exit // (failed again)
module.js:549
throw err;

但是,当我在本地而不是在生产环境中运行此程序时,node server.js可以正常工作,我可以创建多个集群,并且没有错误。该错误是什么意思,为什么它在Heroku / production上失败?谢谢。

0 个答案:

没有答案