title: node.js Amazon s3 how to check file exists
body: <p>I'm trying to figure out how to do the equivalent of fs.exists() on S3.</p>
  
  <p>I succeed in getting the contents of the bucket, but I cannot figure out how to ask S3 if a specific file exists in the bucket (I don't want to download the entire list of files and check client-side, because there are too many files).</p>
  
  <p>For reference: <a href="https://github.com/SaltwaterC/aws2js/wiki/s3.get%28%29" rel="noreferrer">AWS2JS documentation on S3.GET</a></p>
  
  <pre><code>var s3 = require('aws2js').load('s3', appConfig.awsAccessKeyId, appConfig.awsSecretAccessKey);  
  s3.setBucket(appConfig.awsBucketName);
  
              var folder = encodeURI('reports');
              var url = '?prefix=' + folder;
  
              s3.get(url,{Contents: null, Key: 'reports/emot_cat_r1180341142.png'},'xml', function (error, data) {
                  console.log("Error",error);
                  console.log("Data",data);
                  true.should.be.true;
                  done();
              });
  </code></pre>
  
  <p>The output</p>
  
  <blockquote>
    <p>{ Name: 'umusergen',   Prefix: 'reports',   Marker: {},   MaxKeys:
    '1000',   IsTruncated: 'false',   Contents:     [ { Key: 'reports/',
           LastModified: '2013-06-16T17:44:25.000Z',
           ETag: '"d41d8cd98f00b204e9800998ecf8427e"',
           Size: '0',
           Owner: [Object],
           StorageClass: 'STANDARD' },
         { Key: 'reports/emot_cat_r1180341142.png',
           LastModified: '2013-06-16T23:18:59.000Z',
           ETag: '"0b04aa9146d36a447019b1aa94be7eb3"',
           Size: '26374',
           Owner: [Object],
           StorageClass: 'STANDARD' },
         { Key: 'reports/polarity_r1180341142.png',
           LastModified: '2013-06-16T23:19:00.000Z',
           ETag: '"22fd521e0a5e858040082d0d47078532"',
           Size: '23091',
           Owner: [Object],
           StorageClass: 'STANDARD' },
         { Key: 'reports/wordcloud_r1180341142.png',
           LastModified: '2013-06-16T23:19:07.000Z',
           ETag: '"9f7ee9d2fdce5f460b2c42444edd6efc"',
           Size: '167164',
           Owner: [Object],
           StorageClass: 'STANDARD' } ],   '@': { xmlns: { xmlns: '<a href="http://s3.amazonaws.com/doc/2006-03-01/" rel="noreferrer">http://s3.amazonaws.com/doc/2006-03-01/</a>' } } }</p>
  </blockquote>
  
  <p>The "{Contents: null, Key: '[file path/name]'}" is my attempt to interpret the API instructions referenced above.</p>
  
  <p>As you can see, it just enumerates the contents of the bucket, but I need the API call to check for the existence of a specific file. </p>
  
  <p>Can anyone help? I'm fairly new to all this.</p>