0

This seems basic enough, but I can't seem to get it to work.

var access = require( 'fs' ).createWriteStream( 'logs/test.access.log', { flags : 'a' } );

process.stdout.pipe( access );

I'm assuming that when I use console.log() after doing this, wouldn't that message be written to test.access.log? I don't get any errors, but I simply don't get anything in the file as well, so I'm wondering if someone can help me understand streams and writing from stdout to a log file like I have above.

Thanks!

jimlamiell
  • 78
  • 5

1 Answers1

0

Most likely, your Node.js app is closing before the stream's buffer is flushed to disk. This is probably because you're piping the process's own stdout into a file, and stdout normally doesn't close and flush until after Node.js starts to clean up the process.

Try sticking access.destroySoon(); into the end of your code and see if that causes it to flush the data to disk before ending the Javascript event loop.