I recently asked/accepted an answer to a question I had earlier: How can I replicate the functionality of a wget with nodejs.
Now, my script is functioning perfectly, but I’d like to be able to show the user the percentage that’s downloaded. I’m not sure if that’s exposed to us (I didn’t see it in the docs), but I figured I’d ask here anyways. Would love some help!
Thanks!
Yes, you can. With
child_process.spawn. Whilechild_process.execexecutes the command and buffers the output,spawngives you events ondata,errorandend. So you can listen to that and calculate your progress. There’s a basic example in the node docs for spawn.Update: I saw your other question. You can use
wgetfor this, but I recommend the nodejs module request instead. Here’s how to fetch the file with request:If you want to track progress, you pass a callback to
onResponse: