Categories
JavaScript Answers

How to find files by extension, *.html under a folder in Node.js?

Spread the love

To find files by extension, *.html under a folder in Node.js, we use the glob function.

For instance, we write

const glob = require("glob");

glob(__dirname + "/**/*.html", {}, (err, files) => {
  console.log(files);
});

to call glob with the path pattern to search for and a callback that has the files result returned from the search.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *