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

Overview

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)

You might also like...

A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and configure Typescript on it.

A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and configure Typescript on it.

CTSP- Create TS Project A CLI tool to create a NodeJS project with TypeScript CTSP is a CLI tool to make easier to start a new NodeJS project and conf

Sep 13, 2022

This plugin allows you to track the progress of Atlassian Jira issues from your Obsidian notes.

This plugin allows you to track the progress of Atlassian Jira issues from your Obsidian notes.

Obsidian jira-issue This plugin allows you to track the progress of Atlassian Jira issues from your Obsidian notes. Usage Configuration Use the plugin

Dec 30, 2022

Jugglr is a tool for managing test data and running tests with a dedicated database running in a Docker container.

Jugglr Jugglr is a tool for managing test data and running tests with a lightweight, dedicated database. Jugglr enables developers, testers, and CI/CD

Aug 20, 2022

🤗 A CLI for running Stable Diffusion locally via a REST API on an M1/M2 MacBook

Stable Diffusion REST API A CLI for running Stable Diffusion locally via a REST API on an M1/M2 MacBook Pre-requisites An M1/M2 MacBook Homebrew Pytho

Dec 26, 2022

375 DSA Tracker helps you build your confidence in solving any coding related question and helps you prepare for your placements. It is your personal web-based progress tracker based on 375 DSA Sheet by Aman Dhattarwal & Shradha Didi

375 DSA Tracker helps you build your confidence in solving any coding related question and helps you prepare for your placements. It is your personal web-based progress tracker based on 375 DSA Sheet by Aman Dhattarwal & Shradha Didi

375-DSA Tracker 👨‍💻 Me and my friend Abhilash Jena made a 375 DSA Tracker website based on 375 DSA Sheet by Aman Dhattarwal & Shradha Didi which hel

Nov 11, 2022

This repository contains a basic example on how to set up and run test automation jobs with CircleCI and report results to Testmo.

CircleCI test automation example This repository contains a basic example on how to set up and run test automation jobs with CircleCI and report resul

Dec 23, 2021

A simple todo list app written in javascript and html with basic CSS styling This project makes use of webpack to bundle the code. I implemented 3 functionalities on the this project namely: Add task edit task delete task using Js

My To-Do List A simple todo list app written in javascript and html with basic CSS styling This project makes use of webpack to bundle the code. I imp

Nov 11, 2022

Help Ukrainian people find jobs in the EU, navigate visas and translating CVs.

We invite Ukrainians to Europe Since the beginning of war in Ukraine, more than 3.7 million people have left Ukraine, while an estimated seven (7) mil

Nov 12, 2022

A simple Prometheus (aggregated) push gateway allowing stateless/serverless workloads, ephemeral and batch jobs to easily expose their metrics.

A simple Prometheus (aggregated) push gateway allowing stateless/serverless workloads, ephemeral and batch jobs to easily expose their metrics.

Serverless Prometheus (aggregated) Push Gateway A simple Prometheus (aggregated) push gateway allowing stateless/serverless workloads, ephemeral and b

Dec 4, 2022
Comments
  • cleanup after publish

    cleanup after publish

    • Create .gitignore: to make the git repo lighter by untracking unnecessary files
    • Create .npmignore: make the package lighter by removing unnecessary files
    • Update README.md: update the documentation
    opened by mratanusarkar 0
  • convert to node module + add readme

    convert to node module + add readme

    • re-structured codebase
    • renamed files to standard names
    • add assets for README
      • added image samples of progress bar styles
      • added a running demo of the progress bar
    • Create LICENSE
    • Update README.md
    opened by mratanusarkar 0
  • add time conversion to human readable format for progress bar metrics

    add time conversion to human readable format for progress bar metrics

    • added myTimeConverter to convert ms to human readable time
    • added time conversion to myProgressBar metrics
    • added validation and decimal place approximation for ms
    • added toHumanTime() to myProgressBar()
    • added function documentation for toHumanTime()
    opened by mratanusarkar 0
  • modularized code and added more features

    modularized code and added more features

    • converted myProgressBar into a module
    • added feature to resume process from a ith iteration
    • added console.time to measure performance and impact of time for myProgressBar()
    • generalized myProgressBar by adding clearScreenEvery, barLength, style
      • clearScreenEvery: to clear the console every ith iteration
      • barLength: to determine the length of the progress bar
      • style: introduced various ascii styles for the progress bar as seen in various CLIs
    • added sound notification on task complete
    • added feature to work on different OS
      • added input flag to enable/disable sound notification
      • added sound notification to work on windows, linux
      • TODO for macOS (due to lack of system to develop on macOS)
    • added myProgressBar() function documentation
    opened by mratanusarkar 0
Releases(v1.0.4)
Owner
Atanu Sarkar
"An Engineer by profession, Physics lover by passion" | Project Trainee at RBEI | Embedded Systems | IoT | Robotics | Machine Learning | Computer Vision |
Atanu Sarkar
A project where you can keep track of your goal's progress, and contribute to open source in the same time.

Asakatsu-Website A project where you can keep track of your goal's progress, and contribute to open source in the same time. AsaKatsu is a Japanese te

null 8 Dec 27, 2022
Deploy your uAdmin project and host it with a single click (and a few more steps đź‘€) !

Golang and uAdmin CI/CD using ?? Railway! Steps to Deploy Make sure to create a Github account and link it with ?? Railway Click Give your new Reposit

Gaurav Gosain 6 Nov 13, 2022
A flexible gateway for running ML inference jobs through cloud providers or your own GPU. Powered by Replicate and Cloudflare Workers.

Cogflare (Working title) Cogflare is a Cloudflare Workers application that aims to simplify running distributed ML inference jobs through a central AP

NightmareBot 14 Dec 12, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Loops through a list of Discord tokens in a file to check if they are valid/invalid

Discord Token Checker Loops through a list of Discord tokens in a file to check if they are valid/invalid. Click here to report bugs. Usage Download Z

null 319 Dec 31, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A progress bar plugin for tasks in Obsidian.

Obsidian Task Progress Bar A plugin for showing task progress bar near the tasks bullet or headings. Only works in Live Preview mode in Obsidian. Sett

Boninall 52 Dec 31, 2022
Super lighweight, pure JavaScript page load progress bar

Nanobar Super lighweight, pure JavaScript page load progress bar Status View Preview Table of contents Status Quick Start What's included Bugs and fea

The MUDA Organization 5 Jan 3, 2022
Today began learn about MEAN stack first with Nodejs that is a server side form of javascript. Repository for track of Day by Day improvement track in new Skill.

NodeJs Today began learn about MEAN stack first with Nodejs that is a server side form of javascript. Repository for track of Day by Day improvement t

Rahul Bhati 4 Oct 14, 2022