0

I would like to log things to the terminal without writing them to process.stdout or process.stderr so that piping the process doesn't end up being polluted by those logs.

That's very much the equivalent of echo "hello" > /dev/tty in bash (see this question), but I can't find how to directly access /dev/tty from node.

Community
  • 1
  • 1
maxlath
  • 1,734
  • 14
  • 23

2 Answers2

4

Just open it as a file and write to it :)

var fs  = require('fs');
var tty = fs.createWriteStream('/dev/tty');

console.log('hello');
tty.write('foo\n');
tty.write('bar\n');
robertklep
  • 185,685
  • 31
  • 370
  • 359
0

so I found a way, but that could be considered cheating ;)

var exec = require('child_process').exec
process.stdout.write('writing to stdout')
exec("echo 'writing to the terminal without writing to stdout' > /dev/tty")
maxlath
  • 1,734
  • 14
  • 23