workshopper / learnyounode

Learn You The Node.js For Much Win! An intro to Node.js via a set of self-guided workshops.
Other
7.25k stars 1.83k forks source link

Getting error on MAKE IT MODULAR #401

Open krimple opened 8 years ago

krimple commented 8 years ago

I'm on OS X El Capitan - and getting an interesting behavior and wondering if it's me or the scripts.

The output is:
[Error: testing] ERROR: There was a problem printing the solution files: testing

when I execute the verify against my main node source file. It works, and calling it with run brings back the correct output, even with verify as well, but this error occurs at the end:

Your submission results compared to the expected:

                 ACTUAL                                 EXPECTED                
────────────────────────────────────────────────────────────────────────────────

   "CHANGELOG.md"                      ==    "CHANGELOG.md"                     
   "LICENCE.md"                        ==    "LICENCE.md"                       
   "README.md"                         ==    "README.md"                        
   ""                                  ==    ""                                 

────────────────────────────────────────────────────────────────────────────────

[Error: testing]
ERROR: There was a problem printing the solution files: testing

node version: 4.2.3

Sources

file-list-runner.js

var fileList = require('./file-list');

fileList(process.argv[2], process.argv[3],
         function(err, files) {
             if (err) {
                 console.log(err);
             } else {
                 files.forEach(function (f) { console.log(f); });
             }
         });

file-list.js

var fs = require('fs');
var path = require('path');
function listFiles(directory, extension, callback) {
    try {
        fs.readdir(directory, function(err, files) {
            if (err) {
                console.log(err);
                return;
            }
            var filteredList = files.filter(function(file) {
                return path.extname(file) ===  '.' + extension;
            });

            if (filteredList) {
                callback(null, filteredList);
            }
        });
    } catch (error) {
        callback(error);
    }
}

module.exports = listFiles;

I execute with:

learnyounode verify file-list-runner.js
thetwosents commented 8 years ago

Ditto

https://www.dropbox.com/s/25gicekhas8z0iy/Screenshot%202016-01-15%2018.28.00.png?dl=0

robbennet commented 8 years ago

+1 ... going to take a look now

MarkCLaFay commented 8 years ago

+1 same for me as well

agauniyal commented 8 years ago

same error as @thetwosents and the code works with learnyounode run program.js.

program.js contains:

var mymodule = require('./mymodule');

mymodule(process.argv[2], process.argv[3],function (err,file) {
    if(err) { throw err; }
    console.log(file);
});

mymodule.js contains

var fs = require('fs');
var path = require('path');

module.exports = function (dir,ext,callback) {
    fs.readdir(dir, function (err, files) {
        if (err) { return callback(err); }

        var reqExt = '.' + ext;
        files.forEach(function (file) {
            if (path.extname(file) === reqExt){
                callback(null,file);
            }
        });
    });
};
jmalk commented 8 years ago

+1, I am also seeing this error output.

I was able to solve it by following: https://github.com/workshopper/learnyounode/issues/395

YMMV.