# \[SOLVED\] Problem with learnyounode exercise MAKE IT MODULAR

**URL:** <https://forum.freecodecamp.org/t/solved-problem-with-learnyounode-exercise-make-it-modular/31358>\
**Category:** General\
**Created:** [August 26, 2016, 11:49am UTC](https://forum.freecodecamp.org/t/solved-problem-with-learnyounode-exercise-make-it-modular/31358 "2016-08-26T11:49:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pnahratow](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pnahratow/32/164104_2.png) [@pnahratow](https://forum.freecodecamp.org/u/pnahratow)\
**Post date:** [August 26, 2016, 11:49am UTC](https://forum.freecodecamp.org/t/solved-problem-with-learnyounode-exercise-make-it-modular/31358/1 "2016-08-26T11:49:24Z")

</div>

I cannot pass this excercise because it complaines about

```
  ✗ Your additional module file [readdir.js] does not appear to pass back  
  an error received from fs.readdir(). Use the following idiomatic Node.js  
  pattern inside your callback to fs.readdir(): if (err) return  
  callback(err) 

```

When I manually try to execute the program to produce an error it reports it

```
philipp@debian-acer5750g ~/devel/js/fcc/lynode % node program.js adkjvbas 
There was an error Error: ENOENT: no such file or directory, scandir 'adkjvbas'

```

Can someone help me to see what the problem is here?

```
//// file: program.js
const readdir = require("./readdir")
const args = [...process.argv].slice(2);

readdir(args[0], (err, data) => {
    if (err) {
        return console.log("There was an error " + err);
    }
    data.forEach((val) => console.log(val));
}, args[1]);

//// file: readdir.js
const fs = require("fs");
const path = require("path");

module.exports = (dirname, callback, ext) => {
    fs.readdir(dirname, (err, data) => {
        if (err) {
            return callback(err);
        }

        let filteredDir = data.filter((val) => {
            if (ext) {
                return path.extname(val) === "." + ext;
            } else {
                return true;
            }
        })
        callback(null, filteredDir);
    })
}
```

---

<div class="post-metadata">

**Author:** ![JacksonBates](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jacksonbates/32/123402_2.png) [@JacksonBates](https://forum.freecodecamp.org/u/JacksonBates)\
**Post date:** [August 26, 2016, 10:10pm UTC](https://forum.freecodecamp.org/t/solved-problem-with-learnyounode-exercise-make-it-modular/31358/2 "2016-08-26T22:10:52Z")

</div>

I haven’t had my morning coffee yet, so I may be wrong…

I can see you calling a callback function, but you don’t actually define what that callback function should do anywhere.

**Edit**

I have sipped my coffee and think I may be barking up the wrong tree there…give it half a cup and I may have better insights…

---

<div class="post-metadata">

**Author:** ![pnahratow](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pnahratow/32/164104_2.png) [@pnahratow](https://forum.freecodecamp.org/u/pnahratow)\
**Post date:** [August 30, 2016, 5:08pm UTC](https://forum.freecodecamp.org/t/solved-problem-with-learnyounode-exercise-make-it-modular/31358/3 "2016-08-30T17:08:41Z")

</div>

I solved it by trial and error.

Apparently the order of arguments matters. I wrote my function in a way that I can omit the filter extension `(dirname, callback, ext)`. I changed it to `(dirname, ext, callback)` an then it worked.

I don’t understand it though.

---

<div class="post-metadata">

**Author:** ![BenGitter](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bengitter/32/12192_2.png) [@BenGitter](https://forum.freecodecamp.org/u/BenGitter)\
**Post date:** [January 24, 2018, 3:02pm UTC](https://forum.freecodecamp.org/t/solved-problem-with-learnyounode-exercise-make-it-modular/31358/4 "2018-01-24T15:02:46Z")

</div>

Split this topic on January 24, 2018, 3:02pm UTC

A post was split to a new topic: [Learnyounode error](https://forum.freecodecamp.org/t/learnyounode-error/170668)

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 1:09pm UTC](https://forum.freecodecamp.org/t/solved-problem-with-learnyounode-exercise-make-it-modular/31358/5 "2021-01-16T13:09:44Z")

</div>

Closed on January 16, 2021, 1:09pm UTC


