Skip to content

Instantly share code, notes, and snippets.

@pllearns
Created May 1, 2017 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pllearns/6fa1090a7564852fb5c47ea67460bd3c to your computer and use it in GitHub Desktop.
Save pllearns/6fa1090a7564852fb5c47ea67460bd3c to your computer and use it in GitHub Desktop.
Solutions to Learnyounode ---> Make it Modular
'use strict'
var readFile = require('./readFile.js')
var file = process.argv[2]
var filtered = process.argv[3]
readFile(file, filtered, function(err, list) {
if (err) {
return console.log(err)
}
list.forEach(function (list) {
console.log(list)
})
})
var readFile = require('./readFile.js')
var file = process.argv[2]
var filtered = process.argv[3]
readFile(file, filtered, function(err, list) {
if (err) {
console.log(err)
}
list.forEach(function(file) {
console.log(file)
})
})
var fs = require('fs')
var path = require('path')
module.exports = function (dir, stringFind, callback) {
fs.readdir(dir, function (err, list) {
if (err) {
return callback(err)
}
list = list.filter(function (file) {
return path.extname(file) === '.' + stringFind
})
callback(null, list)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment