title: Fast async way to check if file existin nodejs
body: <p>I have used the following async method to check if file exists:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var fs = require('fs');
  
  module.exports.exists = function(path, cb) {
  
    fs.stat(require('path').join(__dirname, '../public', path), function(err, stat) {
      if (err == null) {
        console.log('File exists :' + path);
        cb(true);
      } else if (err.code == 'ENOENT') {
        //file does not exist
        console.log('No file: ' + path);
        cb(false);
      } else {
        console.log('Some other error: ', err.code);
        cb(false);
      }
    });
  
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>If file exists, i redirect to the file in pathStr. If not, display that resource does not exist. Although this is asynchronous, i notice that the web server is much slower and accepts fewer requests with this fs.stat method(if this is commented out, the performance is significantly better). Is there a way in node.js to speed up file exists or not check asynchronously ?</p>