title: Node- Read the content of all files in a directory and directories inside that directory
body: <p>My directory structure is as follows</p>
  
  <pre><code>|demo
    |abc
      abc.js
      abc.html
    |xyz
      test.js
      test.html
    |images
    pqr.js
  </code></pre>
  
  <p>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?</p>
  
  <p>I tried the following code but it won't read the files inside the sub directories</p>
  
  <pre><code>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);
        });
      }
    });
  });
  </code></pre>
  
  <p>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. </p>