title: File retrieval from AWS S3 to Node.js server, and then to React client
body: <p>I have a need to retrieve individual files from Node.js with Express.js. For that, I have installed <code>aws-sdk</code>, as well as <code>@aws-sdk/client-s3</code>. I am able to successfully fetch the file by using this simple endpoint:</p>
  <pre><code>const app = express(),
        { S3Client, GetObjectCommand } = require('@aws-sdk/client-s3'),
        s3 = new S3Client({ region: process.env.AWS_REGION });
  
  app.get('/file/:filePath', async (req,res) =&gt; {
    const path_to_file = req.params.filePath;
  
    try {
      const data = await s3.send(new GetObjectCommand({ Bucket: process.env.AWS_BUCKET, Key: path_to_file }));
      console.log(&quot;Success&quot;, data);
    } catch (err) {
      console.log(&quot;Error&quot;, err);
    }
  });
  </code></pre>
  <p>...but I have no idea how to return the <code>data</code> correctly to the React.js frontend so that the file can be further downloaded. I tried to look up the documentation, but it's looking too messy for me, and I can't even get what does the function return. <code>.toString()</code> method didn't help because it simply returns `&quot;[object Object]&quot; and nothing really else.</p>
  <p>On React, I am using a library <code>file-saver</code>, which works with blobs and provides them for download using a filename defined by user.</p>
  <p>Node v15.8.0, React v16.4.0, @aws-sdk/client-s3 v3.9.0, file-saver v2.0.5</p>
  <p>Thanks for your tips and advices! Any help is highly appreciated.</p>