Simple progress bar
npm install express-progressbarapp.get
JavaScript
const { Handler } = require('express-progressbar');
Handler(p => {
let i = 0;
const int = setInterval(() => {
if (i > 10) {
p.close();
clearInterval(int);
} else {
p.update(i / 10 * 100, {
isCool: true
});
i++;
}
}, 1000);
}, __dirname + '/index.html', '', app, 'WebURL' /, fs, path*/);
`
The passed object is a function that gets called when the server sends a progress event. This function also returns the EventSource.
Take a look at the example files folder for a better explanation.
$3
First you need to import the Progress object from express-progressbar. This is only the Progress class. You need to setup the code on the client-side your self (you can take a look at the example on how to do that).
The Progress constructor's only argument is the response object.
The Progress class has the following functions:
- update Synonym for sendProgress
- end/close: Synonym for closeConnection
- sendProgress: ([Number] percentage, [Object] moreData)
- closeConnection: ([Object] moreData)
- constructSSE: ([Express response object] response, [String] id, [String] data) - This function is not necessary to use.
The client file can now require express-progressbar like this:
`JavaScript
const { Progress } = require('express-progressbar');
app.get('/progress', (request, response) => {
const p = new Progress(response);
let i = 0;
const int = setInterval(() => {
if (i > 10) {
p.close();
clearInterval(int);
} else {
p.update(i / 10 * 100, {
isCool: true
});
i++;
}
}, 1000);
});
``