The directory all my files are in is: \'/usr/home/jordan\' and I have many files under there (in the directory itself, but one file that is named with a .txt extension.
You can use fs.readdir to list the files and find the one that ends with .txt
:
var myPath = "/usr/home/jordan";
fs.readdir(path, function(fileNames) {
for(var i = 0; i < fileNames.length; i++) {
var fileName = fileNames[i];
if(path.extname(fileName) === ".txt") {
fs.readfile(path.join(myPath,fileName), function(err,data) {
console.log(data);
});
break;
}
}
}
);
Note this requires path so add var path = require("path")
at the top.