My node.js
application has a lot of console logs, which are important for me to see (it's quite a big app so runs for a long time and I need to know that things are still progressing) but I'm ending up with thousands of lines of console logs.
Is it somehow possible to do a console.update
that erases/replaces a console line rather than creating a new line?
To create a multi line strings when printing to the JavaScript console, you need to add the new line character represented by the \n symbol. Alternatively, you can also add a new line break using Enter when you use the template literals syntax.
stdout. write() method to print to console without trailing newline.
The most basic and most used method is console. log() , which prints the string you pass to it to the console. If you pass an object, it will render it as a string.
To display a console. log in multiple lines we need to break the line with \n console. log("Hello \n world!"); That will display it like this: Hello world!
Try playing with process.stdout methods instead on console:
process.stdout.write("Hello, World"); process.stdout.clearLine(0); process.stdout.cursorTo(0); process.stdout.write("\n"); // end the line
TypeScript: clearLine()
takes -1, 0, or 1 as a direction parameter with the following meanings:
-1: to the left from cursor.
0: the entire line.
1 - to the right from cursor
Following @michelek's answer, you can use a function somewhat like this:
function printProgress(progress){ process.stdout.clearLine(); process.stdout.cursorTo(0); process.stdout.write(progress + '%'); }
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