learnyounode 题解
//第三题
var fs =require('fs')
var path=process.argv[2]
fs.readFile(path,function(err,data){
var lines=data.toString().split('\n').length-1;
console.log(lines)
})
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
第5题
//new module program.js var mymodule=require('./myfile.js') var dir=process.argv[2] var filter=process.argv[3] mymodule(dir,filter,function(err,list){ if(err) return console.error("ddddddd") list.forEach(function(file) { console.log(file) }) })
//myfile.js var fs =require('fs') var path=require('path') module.exports=function(dir,fileter,callback) { fs.readdir(dir,function(err,list){ if(err) return callback(err) list=list.filter(function(file){ if(path.extname(file)=='.'+fileter) return file }) callback(null,list) }) }
年轻过得闲,以后被人嫌...
年轻累不死....