-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmymodule.js
39 lines (30 loc) · 1.06 KB
/
mymodule.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*These four things are the contract that your module must follow.
* Export a single function that takes exactly the arguments described.
* Call the callback exactly once with an error or some data as described.
* Don't change anything else, like global variables or stdout.
* Handle all the errors that may occur and pass them to the callback.
-callback should be called using the idiomatic node(err, data)
*/
function filterFn(dirname, fileExt, callback) {
var fs = require('fs');
var path = require('path');
// add a '.' to the ext to match the format of path.extname()
var ext = '.' + fileExt;
var returnList = [];
fs.readdir(dirname, function(err, list) {
if(err)
return callback(err, null);
for(var i=0; i<list.length; i+=1) {
if( ext.toLowerCase() === path.extname(list[i]).toLowerCase()) {
returnList.push(list[i]);
}
}
return callback(null, returnList);
})
}
/*
To define a single function export,
you assign your function to the module.exports object,
overwriting what is already there:
*/
module.exports = printExt;