Node.js多次打印到控制台没有换行符

我有一个应用程序上传文件到我的服务器,我正在使用fs和stream我的文件到服务器,并使用查克数据保持跟踪file upload进度。

这里上传示例代码:

 // upload video function uploadVideo(url,file,callback) { let size = fs.lstatSync(file).size; let bytes = 0; let formData = { file: fs.createReadStream(file).on('data', (chunk) => { bytes += chunk.length process.stdout.write(file+filesize(bytes).human()+' of '+filesize(size).human()+' Uploaded'+"\r") }), }; request.post({url:url, json:true, formData: formData}, function optionalCallback(err, httpResponse, body) { if (err) { return callback('upload failed:', err); } callback(null,body); }); } 

正如你所看到的,我正在使用process.stdout.write来显示没有换行的上传进度,并且工作正常。

当我同时上传多个文件时,所有上传进度都会在一行中覆盖,我希望每个上传进度都是分开的。

多重上传示例:

 let files = ['video-1.mp4','video-2.mp4','video-3.mp4','video-4.mp4','video-5.mp4'] // upload multiple file files.forEach((file) => { uploadVideo(url,file,function(err,output){ console.log(output) }) }) 

有一个包: node-progress

它给你这样的东西:

 downloading [===== ] 39/bps 29% 3.7s 

我find了一个叫做multi-progress 多进程的包 。 它确实是我想要的。