How to make loading animation in a console application written in JavaScript or NodeJs?

How to make loading animation in a console application written in JavaScript or NodeJs?

An example of an animation or other animation.

1. -- 2. \ 3. | 4. / 5. -- 
+7
javascript
source share
2 answers

The browser console is really impossible. In Node.js:

 var twirlTimer = (function() { var P = ["\\", "|", "/", "-"]; var x = 0; return setInterval(function() { process.stdout.write("\r" + P[x++]); x &= 3; }, 250); })(); 
+19
source share

You can also do this in the browser console:

 var loading = (function() { var h = ['|', '/', '-', '\\']; var i = 0; return setInterval(() => { i = (i > 3) ? 0 : i; console.clear(); console.log(h[i]); i++; }, 300); })(); // clearInterval(loading) to stop it. 
+2
source share

All Articles