简体   繁体   中英

pm2 + KOA process.send is undefined

I am trying to accomplish the "graceful start" with pm2, but somehow my process.send is always undefined.

I am using esm module and start my application with yarn start

I am logging the process.send, but somehow it is always undefined.

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 .

I guess pm2 needs to start the application with an internal child process in node to make process.send('ready') work.

Changing to "script": "./dist/main.js" for pm2 made it work for me.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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