[freeCodeCamp] Start a Nodejs Server - Complete "Make it Modular"

  _/home/ubuntu/.nvm/versions/node/v4.4.5/lib/node_modules/learnyounode/exer  
  cises/make_it_modular/solution/solution.js_ :  
   
     var filterFn = require('./solution_filter.js')  
     var dir = process.argv[2]  
     var filterStr = process.argv[3]  
       
     filterFn(dir, filterStr, function (err, list) {  
       if (err)  
         return console.error('There was an error:', err)  
       
       list.forEach(function (file) {  
         console.log(file)  
       })  
     }) 
 _/home/ubuntu/.nvm/versions/node/v4.4.5/lib/node_modules/learnyounode/exer  
  cises/make_it_modular/solution/solution_filter.js_ :  
   
     var fs = require('fs')  
     var path = require('path')  
       
     module.exports = function (dir, filterStr, callback) {  
       
       fs.readdir(dir, function (err, list) {  
         if (err)  
           return callback(err)  
       
         list = list.filter(function (file) {  
           return path.extname(file) === '.' + filterStr  
         })  
       
         callback(null, list)  
       })  
     }  

 

posted @ 2016-06-19 17:05  Jonas0608  阅读(214)  评论(0编辑  收藏  举报