Logging stdout and stderr of Node Logging stdout and stderr of Node express express

Logging stdout and stderr of Node


What about this?

console.log("I will goto the STDOUT");console.error("I will goto the STDERR");

Note: both of these functions automatically add new line to your input.

If you don't want those newlines appended to your input, do this

process.stdout.write("I will goto the STDOUT")process.stderr.write("I will goto the STDERR")

Both process.stdout and process.stderr are streams, so you can even pipe a stream into them. See Node.js docs on streams for more info.


You can do this by writing to stdout and stderr streams

process.stdout.write('Hello')

or

process.stderr.write('Error')

Better will be to use some thirdparty logging module like winston or bunyan


The only way I can think of to do this is to spawn a child process (like the fork system call), which then you can "pipe" the output of stderr, stdout to files.

var out = fs.openSync('./output.log', 'a')  , err = fs.openSync('./error.log', 'a');require('child_process').spawn('./server', [], {    detached    : true,    stdio       : ['ignore', out, err]});