[freeCodeCamp] Start a Nodejs Server - Complete "Make it Modular"
Posted Jonas
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[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) }) }
以上是关于[freeCodeCamp] Start a Nodejs Server - Complete "Make it Modular"的主要内容,如果未能解决你的问题,请参考以下文章
FreeCodeCamp:Title Case a Sentence
freeCodeCamp:Factorialize a Number