Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

A Pen by A Non Ymous.

View An-Anonymous-Pen.markdown
1 2
<h2>Notes</h2>
In the learnyounode system, the arguments added via the command line are done invisibly. In other words when I call process.argv anywhere in my program, I'm not typing that in the command line, it is automatically being added. The code below returns the correct result: a list of files from a given directory(argument 1) with a certain extension given by argument 2 (ex. only .md files or .txt files are allowed). My solution is correct, but apparently in my module file, when they test for an error, I'm not returning the error correctly. What am I doing wrong? Thanks in advance.
View An-Anonymous-Pen.markdown
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
/* MODULE.JS */
 
var fs = require('fs');
var path = require('path');
 
module.exports = function(directory, filter, cb) {
 
var results = [];
 
fs.readdir(directory, function(err, data) {
if (err) {
return cb(err);
}
for (var x = 0; x < data.length; x++) {
 
if (path.extname(data[x]) == "." + filter) {
console.log(data[x]);
results.push(data[x]);
}
}
cb(null, results);
});
};
 
 
 
 
/* PROGRAM.JS */
 
var directory = process.argv[2];
var filter = process.argv[3];
var module = require('./module.js');
 
module(directory, filter, function(err, data) {
 
if (err) {
console.log(err);
}
 
for (var x = 0; x < data.length; x++) {
}
 
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.