title: In Node, delete all files older than an hour?
body: <p>I want to delete any files older than an hour.  This is for automatically cleaning up a tmp uploads directory.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>fs.readdir( dirPath, function( err, files ) {
      if ( err ) return console.log( err );
      files.forEach(function( file ) {
          var filePath = dirPath + file;
          fs.stat( filePath, function( err, stat ) {
              if ( err ) return console.log( err );
              var livesUntil = new Date();
              livesUntil.setHours(livesUntil.getHours() - 1);
              if ( stat.ctime &lt; livesUntil ) {
                  fs.unlink( filePath, function( err ) {
                      if ( err ) return console.log( err );
                  });
              }
          });
      });
  });
  </code></pre>
  
  <p>However this just deletes everything in the directory, regardless of whether or not it was uploaded over an hour ago.</p>
  
  <p>Am I misunderstanding how to check the age of the file in Node?</p>