I have the feeling that is probably not possible:
I am trying to print on the terminal text without a new line.
I have tried process.stdout.write
and npm jetty
but they all seem to automatically append a new line at the end.
Is it possible to write to stdout
without having an automatic newline?
Just to be clear: I am not concerned about browsers, I am only interested in UNIX/Linux writing what in C/C++ would be the equivalent of:
std::cout << "blah";
printf("blah");
process.stdout.write()
does not automatically add a new line. If you post precise details about why you think it does, we can probably tell you how you are getting confused, but while console.log()
does add a newline, process.stdout.write()
has no frills and will not write anything you don't explicitly pass to it.
Here's a shell session providing supporting evidence:
echo 'process.stdout.write("123")' > program.js
node program.js | wc -c
3
According to this link process.stdout.write():
console.log
equivalent could look like this:
console.log = function(msg) {
process.stdout.write(`${msg}\n`);
};
So process.stdout.write
should meet your request...
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