TIL getting all files with an extension in Node using Glob
POSTED ON:
TAGS: node file-directory
I wanted to find all json files within a folder structure.
npm i glob
const glob = require('glob');
function getFilesFromPath(path, extension) {
return glob.sync(`${path}/**/*.${extension}`);
}
// get me all .gz files inside the aws directory
const allZippedFiles = getFilesFromPath('./cheerio_data/aws/', "gz");
// get me all the scss files inside the source directory
const allScssFiles = getFilesFromPath('./src/', "scss");
Resources:
Related TILs
Tagged: node