npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

progress-bar-cli

v1.0.4

Published

A CLI ProgressBar for nodeJS and JS to monitor any long running job/process in a loop and alert the user with sound notification when the task ends.

Downloads

419

Readme

NodeJS-ProgressBar

NPM version HitCount NPM downloads MIT License

CLI Progress Bar for NodeJS and JavaScript to track Time, ETA and Steps for any long running jobs in any loops in JS, NodeJS code

Did you ever encounter long running processes or jobs running inside loops in javascript or nodejs? Did you ever encounter tasks where nodejs scripts are running in a server, making multiple api calls in long running loops?

If you are tired of sitting and waiting for these processes and not knowing when this kind of job/loop will end. If you want to have a metrics that will show you the current iteration number of the loop, eta of the job, time elapsed, time to finish, estimated total time along with a cool cli progress bar, and even notify you with an alert sound when the job ends... then you are at the right place!

Here is a running demo of the cli progress bar below:

running demo

Features

The function progressBar() can be applied to any determinate loop with finite and determined loop_len.

It has the following features:

  • you can change and modify the progress bar length
  • you can choose from the list of available cli ascii styles for the progress bar
  • you can resume the progress from the ith iteration (see examples)
  • you can set notify for the progress bar to alert and notify you with sound when the task is complete
  • you can choose to print out every iteration of the progress bar without clearing out the console screen
  • all time information in the progress bar matrices are converted and printed in human readable time

Available matrices:

  • iteration (current-step / total-step)
  • number of iter / sec
  • percentage completion
  • time elapsed
  • estimated time to completion
  • estimated total time

Here are some of the ascii styles you can choose from:

  1. style=0 style 0

  2. style=1 style 1

  3. style=2 style 2

  4. style=3 style 3

  5. style=4 style 4

Installation

npm i progress-bar-cli

Usage

const progressBar = require("progress-bar-cli");

let loop_len = 1000;
let startTime = new Date();
for (i = 0; i < loop_len; ++i) {
    // call progressBar at the start of the loop block
    progressBar.progressBar(i, loop_len, startTime);
    
    /** START OF LONG RUNNING JOB/PROCESS IN LOOP*/
    //
    // Insert your CODE Here!!
    //
    /** END OF LONG RUNNING JOB/PROCESS IN LOOP*/
}

If the job get's haulted in the middle or if the Job was multiple API calls in a loop, and maybe due to network issues the process got haulted, you can trace the last iteration of the running job from log files (if you are maintaining any), and resume the job from that ith iteration using the following code:

const progressBar = require("progress-bar-cli");

let resumeFrom = 50;
let loop_len = 1000;
let startTime = new Date();
for (i = 0; i < loop_len; ++i) {
    // call progressBar at the start of the loop block
    progressBar.progressBar(i, loop_len, startTime);
    
    // code to skip to the ith iteration and continue from there
    if (i < resumeFrom) {
        console.log("> skipping", i);
        continue;
    }
    
    /** START OF LONG RUNNING JOB/PROCESS IN LOOP*/
    //
    // Insert your CODE Here!!
    //
    /** END OF LONG RUNNING JOB/PROCESS IN LOOP*/
}

Function Parameters

Parameter Name | Data Type | default value | description ---------------|-----------|---------------|------------- currentStep | {Number} | *required | the current iteration number in the loop. eg: i, index or count totalSteps | {Number} | *required | total number of steps that the loop will run for. startTime | {Date} | *required | pass the start time of the loop. It should be a Date object. eg: 'new Date()' clearScreenEvery | {Number} | 1 | console to be cleared off every ith iteration of this value. barLength | {Number} | 50 | the length of the progress bar. style | {Number} | 4 | choose styles from 0 - 4. notify | {Boolean} | false | set true for sound alert notification when complete. false to turn it off function return | {Number} | NA | currentStep++

Please Note: * are the three required parameters for the function

Example

Below are some of the example codes where progressBar is used.

  1. using for loop:
const progressBar = require("progress-bar-cli");

// Main for testing the Progress Bar!
let loop_len = 100;
let counter = 0;
let resumeFrom = 0;
let startTime = new Date();

console.time("total system time");
for (i = 0; i < loop_len; ++i) {
    counter = progressBar.progressBar(counter, loop_len, startTime);

    if (counter < resumeFrom) {
        console.log("> skipping", counter);
        continue;
    }

    // do some time consuming task in loop
    var waitTill = new Date(new Date().getTime() + 100);
    while(waitTill > new Date()){}
}
console.timeEnd("total system time");
  1. using while loop
const progressBar = require("progress-bar-cli");

// Main for testing the Progress Bar!
let loop_len = 100;
let counter = 0;
let startTime = new Date();

console.time("total system time");
while (counter < loop_len) {
    counter = progressBar.progressBar(counter, loop_len, startTime);

    // do some time consuming task in loop
    var waitTill = new Date(new Date().getTime() + 100);
    while(waitTill > new Date()){}
}
console.timeEnd("total system time");

Planned features for upcoming version

TODO: add examples in readme for forEach, for/in, for/of, do/while and other types of loops in js and node TODO: add support for async loops in js and node TODO: add support for Indeterminate loops in js and node TODO: add features to make the cli UI even better TODO: add color and spinner if the running console/cli supports colorization TODO: improve the sound alert and support for all OS without any package dependency TODO: replace sound alert system to something different and useful (based on community feedback!) (as the sound feature is not that useful for systems running in server, vm or pipeline based applications)