The node fs package has the following methods to list a directory:
fs.readdir(path, [callback]) Asynchronous readdir(3). Reads the
Basically, you do something like this:
const path = require('path')
const fs = require('fs')
const dirpath = path.join(__dirname, '/path')
fs.readdir(dirpath, function(err, files) {
const txtFiles = files.filter(el => /\.txt$/.test(el))
// do something with your files, by the way they are just filenames...
})