What is the difference between "process.stdout.write" and "console.log" in node.js?
EDIT: Using console.log for a variable showed a lot of unreadable characters while using process.stdout.write showed an object.
Why is that?
log is great for printing messages in the Console. This is what's called the standard output, or stdout . console. error prints to the stderr stream.
write which itself is a buffer stream that will be used to directly print statements on your console. It continuously prints information as retrieved from the stream without adding any new line. It first prints the information being retrieved and then adds a new line.
stdout property is an inbuilt application programming interface of the process module which is used to send data out of our program. A Writable Stream to stdout. It implements a write() method. Return Value: This property continuously prints the information as the data being retrieved and doesn't add a new line.
log() function from console class of Node. js is used to display the messages on the console. It prints to stdout with newline. Syntax: console.log( [data][, ...] ) Parameter: This function contains multiple parameters which are to be printed.
console.log()
calls process.stdout.write
with formatted output. See format()
in console.js for the implementation.
Currently (v0.10.ish):
Console.prototype.log = function() { this._stdout.write(util.format.apply(this, arguments) + '\n'); };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With