Learnyounode "Make It Modular" Typeerror: Undefined is not a function:

262 Views Asked by At

Newer to node, having a really tough time understanding how to create callbacks. I know how to use the ones that come with node decently well, at least on a basic level. In LearnYouNode Make It Modular, I keep getting a TypeError (Undefined is not a function) here on line 10 of my module. Here is my module:

    //Make It Modular

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

module.exports= {
    grab: function(pathFile, ext, callback) {
        ext = '.' + ext;

        fs.readdir(pathFile, function(err, list) { //TypeError
            if(err) throw err;

            var filtered = [];
            list.forEach(function(file) {
                if(path.extname(file) === ext) {
                filtered.push(file);
                }
            })
            return callback(null, filtered);
        });
    }
}

Here is my program:

//Make It Modular
var httpget = require('./httpget');

var dir = process.argv[2];
var ext = process.argv[3];

httpget.grab(dir, ext, function(err, res) {
    for(var i = 0; i < res.length; i++) {
        console.log(res[i]);
    }
});

I'm sure it's super easy... sorry for having to ask.

0

There are 0 best solutions below