Node.js: printing to console without a trailing newline?


Is there a method for printing to the console without a trailing newline? The console object documentation doesn't say anything regarding that:


Prints to stdout with newline. This function can take multiple arguments in a printf()-like way. Example:

console.log('count: %d', count);

If formating elements are not found in the first string then util.inspect is used on each argument.

4/24/2018 10:39:02 PM

Accepted Answer

You can use process.stdout.write():

process.stdout.write("hello: ");

See the docs for details.

8/30/2013 8:15:45 PM

Also, if you want to overwrite messages in the same line, for instance in a countdown, you could add '\r' at the end of the string.

process.stdout.write("Downloading " + data.length + " bytes\r");

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow