简体   繁体   English

如何在Node.js中显示文件写入进度百分比?

[英]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. 上面的代码用于生成CSV文件并将其写入。 This code is working perfectlly. 这段代码可以完美地工作。

But i am trying to show in percentage or anything of progress of writing in csv. 但是我试图以百分比或任何形式显示csv的进度。
and i am trying to show it only in Commandprompt using console.log() 我试图使用console.log()仅在Commandprompt中显示它

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. 如果您使用的是request或http模块,则该库会自动获取流的长度。 You can also pass the length on initiation 您还可以在初始化时传递长度

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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