nodejs 按行读取 readline

 1 //普通读取方法
 2 // var data = fs.readFileSync(versionpath,'utf8');
 3     // var dataarr = data.split(' ');
 4     // dataarr.forEach(function(dataarr) {
 5     //     if( dataarr.indexOf('version') > -1) {
 6     //         version =  (dataarr.split(':')[1]).match(/"(.*)"/)[1];
 7     //         return;
 8     //     }
 9     // })
10 //按行读取
11      // 创建写入临时文件夹
12     if(!fs.existsSync('./yotmp')){
13         fs.mkdirSync('./yotmp');
14     }
15     // tmpPath = './yotmp/version.scss';
16     // fs.writeFileSync(tmpPath, '');
17     var file = fs.createReadStream(versionpath);
18     var out = fs.createWriteStream('./yotmp/varialbes.scss');
19     log(out);
20     var rl = readline.createInterface({
21         input: file,
22         output: out
23     });
24     rl.on('line', function (line){
25         log('line:' + line);
26         if( line.indexOf('version') > -1) {
27             version =  (line.split(':')[1]).match(/"(.*)"/)[1];
28             fsUtil.rmDirSync('./yotmp');
29             log("///////////////");
30             rl.close();
31             return;
32         }
33     });
原文地址:https://www.cnblogs.com/yingwo/p/4493458.html