My directory structure is as follows
|demo
  |abc
    abc.js
    abc.html
  |xyz
    test.js
    test.html
  |images
  pqr.js
I want to read the content of every file in the demo repository and its sub repositories. Need to match a pattern in every file and on a successful match, that entry should go into an array along with the filename. Any suggestions?
I tried the following code but it won't read the files inside the sub directories
var fs=require('fs');
var dir = './demo';
fs.readdir(dir,function(err,files){
  if (err) throw err;
  files.forEach(function(file){
    if(file) {
      fs.readFile('./demo/'+file, 'utf8', function (err,data) {
        if (err) {
          return console.log(err);
        }
        console.log(data);
      });
    }
  });
});
I don't want an array of directories. I want to read the content of every file in the directory and sub directories and match a string. If the string is present, enter it into an array with the filename.
 
     
     
    