简体   繁体   English

pm2 + KOA process.send 未定义

[英]pm2 + KOA process.send is undefined

I am trying to accomplish the "graceful start" with pm2, but somehow my process.send is always undefined.我试图用 pm2 完成“优雅的开始”,但不知何故我的 process.send 总是未定义。

I am using esm module and start my application with yarn start我正在使用esm模块并使用yarn start启动我的应用程序

I am logging the process.send, but somehow it is always undefined.我正在记录 process.send,但不知何故它总是未定义。

app.listen(port, () => {
  console.log('process.send', process.send);
  console.log(`Server running on port ${port}`);
});

Where could be the problem?问题可能出在哪里?

Thanks and best regards谢谢和最好的问候

I had the same issue with an application using npm start as script in pm2 .我在pm2 中使用npm start作为脚本的应用程序遇到了同样的问题。

I guess pm2 needs to start the application with an internal child process in node to make process.send('ready') work.我猜pm2需要使用节点中的内部子进程启动应用程序以使process.send('ready')工作。

Changing to "script": "./dist/main.js" for pm2 made it work for me.更改为"script": "./dist/main.js"PM2使得它为我工作。

So maybe changing your config and application to something like this:因此,也许将您的配置和应用程序更改为如下所示:

module.exports = {
  apps: [
    {
      name: 'myApp',
      script: './dist/main.js',
      time: true,
      listen_timeout: 10000,
      env: { environment: 'production', NODE_ENV: 'production', },
    }
  ],
}; 

(Depending of the output from your build) (取决于构建的输出)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM