
Product
Introducing Supply Chain Attack Campaigns Tracking in the Socket Dashboard
Campaign-level threat intelligence in Socket now shows when active supply chain attacks affect your repositories and packages.
p-progress
Advanced tools
Create a promise that reports progress
Useful for reporting progress to the user during long-running async operations.
$ npm install p-progress
const PProgress = require('p-progress');
(async () => {
const progressPromise = new PProgress((resolve, reject, progress) => {
const job = new Job();
job.on('data', data => {
progress(data.length / job.totalSize);
});
job.on('finish', resolve);
job.on('error', reject);
});
progressPromise.onProgress(progress => {
console.log(`${progress * 100}%`);
//=> 9%
//=> 23%
//=> 59%
//=> 75%
//=> 100%
});
await progressPromise;
})();
Same as the Promise constructor, but with an appended progress parameter in executor.
PProgress is a subclass of Promise.
Type: Function
Call this with progress updates. It expects a number between 0 and 1.
Multiple calls with the same number will result in only one onProgress()
event.
Calling with a number lower than previously will be ignored.
Progress percentage 1 is reported for you when the promise resolves. If you set it yourself, it will simply be ignored.
Type: number
The current progress percentage of the promise as a number between 0 and 1.
Accepts a function that gets instance.progress as an argument and is called for every progress event.
Convenience method to make your promise-returning or async function report progress.
The function you specify will have the progress() function appended to its parameters.
const PProgress = require('p-progress');
const runJob = PProgress.fn(async (name, progress) => {
const job = new Job(name);
job.on('data', data => {
progress(data.length / job.totalSize);
});
await job.run();
});
(async () => {
const progressPromise = runJob('Gather rainbows');
progressPromise.onProgress(console.log);
//=> 0.09
//=> 0.23
//=> 0.59
//=> 0.75
//=> 1
await progressPromise;
})();
Convenience method to run multiple promises and get a total progress of all of them. It counts normal promises with progress 0 when pending and progress 1 when resolved. For PProgress type promises, it listens to their onProgress() method for more fine grained progress reporting. You can mix and match normal promises and PProgress promises.
const PProgress = require('p-progress');
const delay = require('delay');
const progressPromise = PProgress.fn(async progress => {
progress(0.14);
await delay(52);
progress(0.37);
await delay(104);
progress(0.41);
await delay(26);
progress(0.93);
await delay(55);
});
const allProgressPromise = PProgress.all([
delay(103),
progressPromise(),
delay(55),
delay(209)
]);
(async () => {
allProgressPromise.onProgress(console.log);
//=> 0.0925
//=> 0.3425
//=> 0.5925
//=> 0.6025
//=> 0.7325
//=> 0.9825
//=> 1
await allProgressPromise;
})();
Type: Promise[]
Array of promises or promise-returning functions, similar to p-all.
Type: object
Type: number
Default: Infinity
Minimum: 1
Number of concurrently pending promises.
To run the promises in series, set it to 1.
When this option is set, the first argument must be an array of promise-returning functions.
FAQs
Create a promise that reports progress
The npm package p-progress receives a total of 1,313 weekly downloads. As such, p-progress popularity was classified as popular.
We found that p-progress demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Campaign-level threat intelligence in Socket now shows when active supply chain attacks affect your repositories and packages.

Research
Malicious PyPI package sympy-dev targets SymPy users, a Python symbolic math library with 85 million monthly downloads.

Security News
Node.js 25.4.0 makes require(esm) stable, formalizing CommonJS and ESM compatibility across supported Node versions.