Difference between process.stdout.write and console.log in node.js?
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');
};
A way to output logs without using process.stdout.write in Node JS?
Looks like debug module on npm writes to stderr
instead:
By default debug will log to stderr
/**
* Invokes `util.format()` with the specified arguments and writes to stderr.
*/
function log(...args) {
return process.stderr.write(util.format(...args) + '\n');
}
What's the difference between console.log and response.write?
console.log
puts the data on the standard output (file descriptor number 1).
response.write
write the data on the response
object, whatever it is. In your case it seems to be a response to an HTTP request, but it may be any other stream (including standard output).
The results of both of those commands can end up in the same place - like your screen - but taking a different path to the same destination: console.log
doesn't use the network in the process but response.write
(most likely) does. I say "most likely" because it is not clear from your question what this response
is a response to.
Process.stdout.write appends true to the console output
I think you need to take another look at your code. some of the common advice for programming forums is to get an example simplified enough that your problem still occurs.
In this case if I write process.stdout.write('hello')
to a file, and then ask node to run that file, I get the correct response of hello
back, the word true doesn't show up.
According to the options from node, using -p
instead of -e
means you're asking it to print the result of that function call, which was a success.
-e, --eval script evaluate script
-p, --print evaluate script and print result
For now try the -e
flag with your code.
Related Topics
Understanding JavaScript Scope with "Var That = This"
Date Parsing in JavaScript Is Different Between Safari and Chrome
Differencebetween Document and Document in JavaScript
How to Create a Hash or Dictionary Object in JavaScript
Script Tag in Angular2 Template/Hook When Template Dom Is Loaded
Settimeout/Cleartimeout Problems
Passing in Dynamic Key:Value Pairs to an Object Literal
How to Filter by Object Property in Angularjs
Detect When User Accepts to Download a File
Password-Check Directive in Angularjs
Difference Between Dot Notation and Bracket Notation in JavaScript
JavaScript Custom Event Listener
Why Not Always Use the Index as the Key in a Vue.Js for Loop
How Do the JavaScript Relational Comparison Operators Coerce Types
How to Update React Context from Inside a Child Component
Wrapping Lines/Polygons Across the Antimeridian in Leaflet.Js