Timeline for Node.js: printing to console without a trailing newline?
Current License: CC BY-SA 4.0
13 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 6 at 7:24 | comment | added | M Imam Pratama | Caveat: If the new line is shorter than the previous line, some of the old characters will be kept in the terminal. | |
Aug 2, 2021 at 13:19 | history | edited | Yoav Kadosh | CC BY-SA 4.0 |
added 8 characters in body
|
Jul 27, 2021 at 9:09 | comment | added | Antoine Weber |
using @DaveF indication, I get this working process.stdout.clearLine(); process.stdout.cursorTo(0); process.stdout.write("Downloading " + i + " bytes\r")
|
|
Apr 7, 2021 at 1:56 | comment | added | Dave F |
This didn't work for me. I used: process.stdout.clearLine(); process.stdout.cursorTo(0); . I'm not certain if using the carriage return is a hack, but clearLine() and cursorTo() are found within the node.js documentation
|
|
Feb 1, 2018 at 19:46 | comment | added | dewey |
With ANSI escape codes as mentioned above, you can clear the line with .write("\x1b[0G\x1b[K"); . Or without changing cursor position .write("\x1b[2K") .
|
|
Jul 24, 2017 at 17:04 | comment | added | Dan Dart |
You could first write spaces, for instance you could write ''.padEnd(str.length) where str is your original string to overwrite, then do your hello .
|
|
Jan 18, 2017 at 13:55 | comment | added | oooyaya |
This is great but how do you make it clear the contents of the line first? .write("goodbye\r") followed by .write("hi\r") results in hiodbye
|
|
Feb 18, 2016 at 11:05 | comment | added | daremkd | Just put the \r at the beginning rather than at the end of the string to make it work in Windows. | |
Sep 22, 2015 at 2:10 | comment | added | some |
To make the ansi escape code given above in a comment by @GarciadelCastillo to work in strict mode, replace the octal literal \033 with the hex literal \x1b like this: \x1b[0G . (that works with both strict and non-strict code)
|
|
Apr 7, 2014 at 15:13 | comment | added | GarciadelCastillo |
For Windows, you can use the equivalent code '\033[0G', as in: process.stdout.write("Downloading " + data.length + " bytes\033[0G");
|
|
Sep 1, 2013 at 6:50 | comment | added | chowey | This does not work on Windows for me. But works great on non-dows. | |
Jun 14, 2013 at 21:18 | comment | added | longda | Although not the answer to the question, this is an amazing answer. Can't wait to try. | |
Mar 9, 2012 at 4:26 | history | answered | defvol | CC BY-SA 3.0 |