{"action":"created","issue":{"url":"https://api.github.com/repos/nodeschool/discussions/issues/1037","labels_url":"https://api.github.com/repos/nodeschool/discussions/issues/1037/labels{/name}","comments_url":"https://api.github.com/repos/nodeschool/discussions/issues/1037/comments","events_url":"https://api.github.com/repos/nodeschool/discussions/issues/1037/events","html_url":"https://github.com/nodeschool/discussions/issues/1037","id":64972892,"number":1037,"title":"'Make it modular' question","user":{"login":"psychoche","id":473771,"avatar_url":"https://avatars.githubusercontent.com/u/473771?v=3","gravatar_id":"","url":"https://api.github.com/users/psychoche","html_url":"https://github.com/psychoche","followers_url":"https://api.github.com/users/psychoche/followers","following_url":"https://api.github.com/users/psychoche/following{/other_user}","gists_url":"https://api.github.com/users/psychoche/gists{/gist_id}","starred_url":"https://api.github.com/users/psychoche/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/psychoche/subscriptions","organizations_url":"https://api.github.com/users/psychoche/orgs","repos_url":"https://api.github.com/users/psychoche/repos","events_url":"https://api.github.com/users/psychoche/events{/privacy}","received_events_url":"https://api.github.com/users/psychoche/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-28T18:26:28Z","updated_at":"2015-03-29T08:02:57Z","closed_at":null,"body":"Hi all! \r\n\r\nI'm stuck on module part in learnyounode. \r\nHere is my code from 'Filtered ls':\r\n\r\n```\r\nvar fs = require('fs');\r\nvar path = require('path');\r\n\r\n fs.readdir(process.argv[2], function  myDir (err, list){\r\n        if (err) throw err;\r\n        for(var i = 0; i < list.length; i++){\r\n            if (path.extname(list[ i]) == \".\" + process.argv[3]){\r\n                 console.log(list[i]);\r\n             }\r\n         }\r\n    });\r\n```\r\nIt's working. But I can't move it to module.\r\nHere is my mymodule.js:\r\n```\r\nvar fs = require('fs');\r\nvar path = require('path');\r\n\r\nmodule.exports =  fs.readdir(process.argv[2], function (err, list){\r\n      if (err) throw err;\r\n         for(var i  = 0; i < list.length; i++){\r\n              if  (path.extname(list[i]) == \".\" + process.argv[3]){\r\n                   return list[i];\r\n              }\r\n         }\r\n });\r\n```\r\nI understand that this is incorrect. But I can't realize how to make it work.\r\nPlease help. Thank you!\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/nodeschool/discussions/issues/comments/87369512","html_url":"https://github.com/nodeschool/discussions/issues/1037#issuecomment-87369512","issue_url":"https://api.github.com/repos/nodeschool/discussions/issues/1037","id":87369512,"user":{"login":"psychoche","id":473771,"avatar_url":"https://avatars.githubusercontent.com/u/473771?v=3","gravatar_id":"","url":"https://api.github.com/users/psychoche","html_url":"https://github.com/psychoche","followers_url":"https://api.github.com/users/psychoche/followers","following_url":"https://api.github.com/users/psychoche/following{/other_user}","gists_url":"https://api.github.com/users/psychoche/gists{/gist_id}","starred_url":"https://api.github.com/users/psychoche/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/psychoche/subscriptions","organizations_url":"https://api.github.com/users/psychoche/orgs","repos_url":"https://api.github.com/users/psychoche/repos","events_url":"https://api.github.com/users/psychoche/events{/privacy}","received_events_url":"https://api.github.com/users/psychoche/received_events","type":"User","site_admin":false},"created_at":"2015-03-29T08:02:57Z","updated_at":"2015-03-29T08:02:57Z","body":"Thank you! \r\nI got it to work. \r\nmymodule.js:\r\n```\r\n 1 var fs = require('fs');\r\n  2 var path = require('path');\r\n  3\r\n  4 module.exports = function(dirName, extName, callback) {\r\n  5\r\n  6     fs.readdir(dirName, function (err, list){\r\n  7       if (err) return callback(err);\r\n  8       var result = [];\r\n  9         for(var i = 0; i < list.length; i++){\r\n 10              if  (path.extname(list[i]) == \".\" +  extName){\r\n 11                 result.push(list[i]);\r\n 12              }\r\n 13         }\r\n 14\r\n 15         callback(null, result);\r\n 16     });\r\n 17 };\r\n```\r\n\r\nfilteredls-m.js\r\n```\r\n 1 var mymodule = require('./mymodule.js');\r\n  2\r\n  3 var dirName = process.argv[2].toString();\r\n  4 var extName = process.argv[3].toString();\r\n  5\r\n  6 mymodule(dirName, extName, function(err,data){\r\n  7     if (err)\r\n  8         return console.error('There was an error:', err);\r\n  9     for(var i = 0; i < data.length; i++) {\r\n 10         console.log(data[i]);\r\n 11     }\r\n 12 });\r\n```\r\nBut I still don't understand this stuff with modules and callbacks. Can you point me to some good information about this?\r\nThank you again.\r\n\r\n--\r\nBest regards\r\nPavel Letskiy"}}