Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A Pen by A Non Ymous.
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.
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) {
cb(null, results);
var directory = process.argv[2];
var filter = process.argv[3];
var module = require('./module.js');
module(directory, filter, function(err, data) {
if (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