Let’s just stash this here…

Javascript code snippet for node.js to display a looping busy indicator on the console output.


What it does

First define the characters for the loop: |/―\\. Can be any ASCII character you like.

Next iterate the characters, wait ms time before each character and reset the index to 0 at the end of the chars.

Then write the string to the console. When you use console.log each change is written on a new line, because that appends \n to the output. With process.stdout.write you can use \r to reset the cursor to the beginning of the line and then overwrite the displayed characters. The space at the end is there only for good looks.

Related stuff

Categories: Code


Alex · 21 July 2016 at 16:07

I am impressed!!! Gonna use for my node based youtube video downloader project

    Franklin · 24 July 2016 at 19:02

    Thanks!! And goodluck

Leave a Reply

Your email address will not be published. Required fields are marked *