Nodejs Monitoring Statistics within terminal

sorry if this been asked somewhere else. Ive been trying to find something similar to what i want but i cant seem to find it anywhere, so figured i asked.

I have a script in nodejs using puppeteer and i want to be able to see statistics without having terminal scroll down printing new lines to show me new numbers.

For example:

puppeteer cluster statistic monitoring

I basically want to do this but customize it to my needs. But, anywhere i find all i can see is a webserver to connect to. I rather just keep it within the terminal where it could update values and not print new lines every time a value updates.

For example:

Users: 79        Tries: 1728
OnGoing: 8       Passed: 1500
Idle: 71         Failed: 228

Upvotes: 0

Views: 149

Answers (1)

Ahmed Hekal
Ahmed Hekal

Reputation: 478

I think you can do it simply by clearing stdout and moving cursor to the first line and rewriting your output with every update ecc...

for example

let progress = 0
setInterval(()=>{
    let output = ""
    for (let index = 0; index < progress; index++) {
        output+="="
        
    }
    output +=">"
    process.stdout.clearLine(0);
    process.stdout.cursorTo(0);
    process.stdout.write(output+(progress++)+"%");

},1000)


Upvotes: 1

Related Questions