node 一行一行的读取文件

const request = require('request')
const readline = require('readline');
var path = require('path');
const fs = require('fs')
const r1 = readline.createInterface({
    input: fs.createReadStream("imgList.txt")
  });
  r1.on('line', function(line){
    var url = line
        reg = /http:\/\/[.\w]+\/([.\w]+)\?.*/
        let writeStream=request(url).pipe(fs.createWriteStream('./img/'+reg.exec(url)[1]))
        writeStream.on('end', function () {
            console.log('结束了=====');
        }) ;
  })

 

posted @ 2020-09-05 16:26  酷酷的城池  阅读(655)  评论(0编辑  收藏  举报