简体   繁体   中英

How to show file writing progress percentage in nodejs?

var csv = json2csv(datas, fields);
  var path = './final_' + Date.now() + '.csv';
  fs.writeFile(path, csv, function (err, data) {
    if (err) { throw err; }
    else {
      console.log('File created >> ' + path)
    }
  });

Above code is use for generating CSV file and writing into it. This code is working perfectlly.

But i am trying to show in percentage or anything of progress of writing in csv.
and i am trying to show it only in Commandprompt using console.log()

How can i achive this?

You can use progress-stream library in order to see upload file progress in percentage. This library should get your things done.

This library gets the length of the stream automatically if you're using the request or http module. You can also pass the length on initiation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM