Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Learnyounode Make it Moduler Failing #1967

Closed
chandrakantkr91 opened this issue Jan 10, 2017 · 3 comments
Closed

Learnyounode Make it Moduler Failing #1967

chandrakantkr91 opened this issue Jan 10, 2017 · 3 comments

Comments

@chandrakantkr91
Copy link

Notes

Please delete this section after reading it

If you have a problem with an error message:

  • node version: <run "node -v" in you terminal and replace this>
  • npm version: <run "npm -v" in you terminal and replace this>
  • os: windows 7/windows 10/mac/linux

Error output


 ✓

 Submission results match expected

 ✓

 Additional module file exports a single function

 ✓

 Additional module file exports a function that takes 3 arguments

 ✗

 Your additional module file [mymodule.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)

 # FAIL Your solution to MAKE IT MODULAR didn't pass. Try again!

My Code

var fs = require('fs');
var path = require('path');
var mymodule = require('./mymodule.js');
var folder = process.argv[2];
var ext = '.'+process.argv[3];

function test(err, data){
  if(err)
  return console.error(err)
  else {
    data.forEach(function(d){
      console.log(d);
    })
  }
}

mymodule(folder, ext, test);


```mymodule.js

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

var farr=[];

module.exports = function (folder, ext, callback){

  fs.readdir(folder, 'utf8', function(err, data){
    if (err) return console.error(err)

    data.forEach(function(d){
      if(path.extname(d) === ext)
      farr.push(d);
    })
    callback(null, farr)
  })
}
@Rud156
Copy link

Rud156 commented Jan 16, 2017

Don't know if you completed the challenge or not. You have problem in calling the readdir method.
Remove the encoding that you have provided it does not require an encoding. Also in handling the error call your callback function instead of console.error(error).
Also in your main code don't add the '.' there add the '.' in mymodule.js.

@stale stale bot added the inactive label Sep 12, 2017
@stale
Copy link

stale bot commented Sep 12, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot closed this as completed Sep 19, 2017
@stale
Copy link

stale bot commented Sep 19, 2017

This issue is being automatically closed due to inactivity. Please feel to re-open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants