3

I have a simple nodejs docker service. I'm watching stdout in development and logging to AWS cloudwatch in production.

I've just added forever-monitor, but that breaks my logging. So I've started catching stdout on 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 me byte code out -

[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 get my console.log statements back into std-out?

Aidan Ewen
  • 13,049
  • 8
  • 63
  • 88

1 Answers1

0

It looks like data is a stream (see node docs).

I've updated my code to -

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

And now it's working as expected. (I found this question useful).

Aidan Ewen
  • 13,049
  • 8
  • 63
  • 88