The node fs package has the following methods to list a directory:
fs.readdir(path, [callback]) Asynchronous readdir(3). Reads the
I used the following code and its working fine:
var fs = require('fs');
var path = require('path');
var dirPath = path.resolve(__dirname); // path to your directory goes here
var filesList;
fs.readdir(dirPath, function(err, files){
filesList = files.filter(function(e){
return path.extname(e).toLowerCase() === '.txt'
});
console.log(filesList);
});