title: Best way to manage log file
body: <p>I would like to know what is the best way to manage log file in node.js. I my case, my application read all files in a directory (each file can have more than 1000 lines) and then send request for each line of each file. Now I would like to save all requests results in my log file. </p>
  
  <p>I am hesitating between write a result after each request as below:</p>
  
  <pre><code>fs.readdir(dir, function (err, filenames) {
      filenames.forEach(async function (filename) {
             let data = fs.readFileSync(filename, 'utf8');
             let result = await query.send(data);
             log(result);
      });
  });
  </code></pre>
  
  <p>or save all results in an array and then write it in the log file after the process:</p>
  
  <pre><code>let array = []; let counter = 0;
  fs.readdir(dir, async function (err, filenames) {
      for(filename of filenames) {
          let data = fs.readFileSync(filename, 'utf8');
          let result = await query.send(data)
          array.push(result);
          counter++;
          if(counter === filenames.length) {
               // loop array and log all results
          }
      }
  });
  </code></pre>
  
  <p>What is the best solution for better performance ?</p>
  
  <p>Any others suggestions will be greatly appreciated</p>