node.js - cannot pass learnyounode: is the callback function used uncorrectly? -
i trying solve sixth problem of learnyounode needs module file print file list. here 2 files:
the main file program.js
:
var mymodule = require('./module.js'); mymodule(process.argv[2], process.argv[3], function(err, file){ if(err){ console.log(err); return; } console.log(file); });
the module file module.js
:
var fs = require('fs'); var path = require('path'); var fileext; module.exports = function(dir, ext, callback) { fs.readdir(dir, function(err, files){ if(err){ callback(err); return; } files.foreach(function(file){ fileext = path.extname(file).substring(1); if(fileext === ext){ callback(null, file); } }); }); }
but throws error:
processors[i].call(self, mode, function (err, pass) { typeerror: cannot read property 'call' of undefined
what doing wrong?
the instructions state need call callback
once, array containing of matching files. in case, calling callback
once every matching file.
i'd include sort of code example, i'll omit in order continue learning journey. if require code specifics, ask.
wiki
Comments
Post a Comment