node.jsprocesspm2koa2

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


Solution

  • 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)