find files by extension, *.html under a folder in nodejs

后端 未结 14 808
隐瞒了意图╮
隐瞒了意图╮ 2020-12-07 23:57

I\'d like to find all *.html files in src folder and all its sub folders using nodejs. What is the best way to do it?

var folder = \'/project1/src\';
var ex         


        
14条回答
  •  伪装坚强ぢ
    2020-12-08 00:26

    Old post but ES6 now handles this out of the box with the includes method.

    let files = ['file.json', 'other.js'];
    
    let jsonFiles = files.filter(file => file.includes('.json'));
    
    console.log("Files: ", jsonFiles) ==> //file.json
    

提交回复
热议问题