The following is exercise 5 of the student learning module for students
Create a program that prints a list of files in a given directory, filtered by file extension. You will be given the directory name as the first application to your program (for example /path/to/dir/) and the file extension for filtering by the second argument.
For example, if you get "txt" as the second argument, you will need to filter the list only for files ending in .txt.
The list of files must be printed to the console, one file per line and must use asynchronous I / O.
var fs = require('fs');
var path = require('path');
var mydir = process.argv[2];
var ext1 = process.argv[3]
fs.readdir(mydir, function(err, files){
if(err){
throw err
}
files.forEach(function(filename){
var ext = path.extname(filename);
if(ext == ext1){
console.log(filename);
}
});
});
, , , learnyounode,
, . - plz???