title: Get the most recent file in a directory, Node.js
body: <p>I am trying to find the most recently created file in a directory using Node.js and cannot seem to find a solution. The following code seemed to be doing the trick on one machine but on another it was just pulling a random file from the directory - as I figured it might. Basically, I need to find the newest file and ONLY that file.</p>
  
  <pre><code>var fs = require('fs'); //File System
  var audioFilePath = 'C:/scanner/audio/'; //Location of recorded audio files
      var audioFile = fs.readdirSync(audioFilePath)
          .slice(-1)[0]
          .replace('.wav', '.mp3');
  </code></pre>
  
  <p>Many thanks!</p>