I'm pretty new to JS and Node so it might be a dumb question. Ive look everywhere and I can't figure how to get a response from the Server. The goal is to be able to do a progress bar so I need to return the bytes download / Total bytes.
For now i'm able to have the information but only on the server, I can't figure how to send it to the front end.
Heres what I did so far.
Server.js
app.get('/', async (req, res) => {
const response =
fetch(`https://api.github.com/repos/${options.gitUser}/${options.gitRepo}/releases/latest`)
.then(response => response.json()).then(data => { json = data; })
.then(() => {
let zip;
for (i = 0; i < json['assets'].length; i++) {
if (json['assets'][i]['name'] === `${options.softName}`) zip = json['assets'][i];
}
let received_bytes = 0;
let total_bytes = 0;
var req = request(
{
method: 'GET',
uri: zip['browser_download_url']
}
);
var out = fs.createWriteStream(`C:\\Users\\${options.userName}\\AppData\\Roaming\\Camnor\\Camsoft\\${options.softName}`);
req.pipe(out);
req.on('response', data => {
total_bytes = parseInt(data.headers['content-length']);
});
req.on('data', chunk => {
received_bytes += chunk.length;
console.log(received_bytes, total_bytes); <== The data I want in the front end
});
});
})
On the client side I just call
Neutralino.os.execCommand('server-win.exe'); const response = fetch('http://localhost:3000') Ive try a lot of thing but I can't figure how to send the information to the front end. The zip file is downloaded properlly on the correct folder. Everything else work. Thanks