码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2016-06-19 18:27:06      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

  _/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)  
       })  
     }  

 

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

标签:

原文地址:http://www.cnblogs.com/tianhangzhang/p/5598368.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!