Search code examples
javascriptnode.jsstdoutstderr

How can I write blocking in stdout with node.js?


I'm writing a node.js application which stdout is piped to a file. I'm writing everything with console.log. After a while my Application reaches the 1GB Limit and stops. The interesting thing is, that if I use console.error instead of console.log, the memory usage keeps low and the programm runs fine. So it looks like node.js can't flush the stdout stream and everything is kept in memory. I wanna keep stderr free for errors.

My Question is:

Is there a way to write blocking into stdout? Or at least, can I write with a callback to stdout, so I can ensure I'm writing not too much?

thx!


Solution

  • If you really really want synchronous writes to stdout you can do:

    var fs = require('fs');
    fs.writeSync(1, "Foo\n");
    fs.fsyncSync(1);