To make Node pm2 log to console, we call connect
.
For instance, we write
const pm2 = require("pm2");
pm2.connect((err) => {
if (err) {
console.error(err);
process.exit(2);
}
pm2.start(
[
{
script: "server.js",
output: "/dev/stdout",
error: "/dev/stderr",
},
],
(err, proc) => {
if (err) {
throw err;
}
}
);
});
to call connect
with a callback that calls start
with some options.
We set output
to the location to '/dev/stdout'
to log to the console.
And we log errors to '/dev/stderr'
by setting error
to "/dev/stderr"
.