How to use npm forever-monitor to log into stdout

I have a simple nodejs dock. I am looking at stdout in development and logging to AWS cloudwatch in production.

I just added a permanent monitor, but that breaks my log. So I started catching stdout in the child process,

const forever = require('forever-monitor');

const child = new (forever.Monitor)('server.js', {
  max: 3,
  silent: true,
  args: []
});

child.on('stdout', function(data) {
  console.log(data);
});

      

but that just gives out the byte code -

[nodemon] starting `node forever.js`
<Buffer 63 6f 6e 6e 65 63 74 65 64 20 74 6f 20 6c 69 76 65 20 64 62 0a>

      

How do I return expressions console.log

to std-out?

+3


source to share


1 answer


It looks like it data

is a stream (see node docs ).

I have updated my code to -



child.on('stdout', function(data) {
  console.log(data.toString());
});

      

And now it works as expected. (I found this question helpful).

0


source







All Articles