Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between "process.stdout.write" and "console.log" in node.js?

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?

like image 401
ajsie Avatar asked Feb 12 '11 05:02

ajsie


People also ask

Does console log go to stdout?

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.

What does process stdout write do?

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.

What is stdout in node JS?

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.

What is console log in node JS?

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.


1 Answers

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'); }; 
like image 85
TK-421 Avatar answered Oct 13 '22 21:10

TK-421