Make pm2 log to console

前端 未结 4 1018
滥情空心
滥情空心 2020-12-30 20:44

I am running a node webserver using pm2. Since pm2 spawns another process and redirects stdout and stderr to files, I have to look somewhere else for the logs. Ideally, I wo

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-30 21:12

    programmatically you can do something like this:

    const pm2 = require('pm2')
    
    pm2.connect(function(err) {
      if (err) {
        console.error(err);
        process.exit(2);
      }
      pm2.start([
        {
          script             : "server.js",
          output: "/dev/stdout",
          error: "/dev/stderr",
        },
      ]
        , function(err, proc) {
          if(err) {
            throw err
          }
        });
    })
    

提交回复
热议问题