The node fs package has the following methods to list a directory:
fs.readdir(path, [callback]) Asynchronous readdir(3). Reads the
You could filter they array of files with an extension extractor function. The path module provides one such function, if you don't want to write your own string manipulation logic or regex.
var path = require('path');
var EXTENSION = '.txt';
var targetFiles = files.filter(function(file) {
return path.extname(file).toLowerCase() === EXTENSION;
});
EDIT
As per @arboreal84's suggestion, you may want to consider cases such as myfile.TXT, not too uncommon. I just tested it myself and path.extname does not do lowercasing for you.