title: How to download a file from Amazon S3 bucket in node.js synchronously
body: <p>I have to download multiple files from S3 bucket using node.js. For that I have to write a <code>for loop</code> &amp; call the <code>s3.getObject(param)</code> method to download. After the files are downloaded I have to merge their contents. </p>
  
  <p>I have written like this:</p>
  
  <pre><code>var fileContentList = new ArrayList();
  
  for(i=0; i&lt;fileNameList.length i++){
      s3.getObject({ Bucket: "my-bucket", Key: fileNameList.get(i) }, function (error, data) {
      if (error != null) {
        alert("Failed to retrieve an object: " + error);
      } else {
        alert("Loaded " + data.ContentLength + " bytes");
        fileContentList.add(data.Body.toString());
      }
    }
  );
  }
  
  //Do merging with the fileContentList.
  </code></pre>
  
  <p>But as <code>s3.getObject</code> is an asynchronous call the current thread moves on &amp; nothing gets added to the <code>fileContentList</code> while I am doing the merging. </p>
  
  <p>How can I solve the problem? Any idea?<br>
  Is their any synchronous method in aws-sdk to download file?</p>