title: How to decode a Base64 file on the client side from JSON response?
body: <p>I have an application that renders a file on the server side. I am passing it as &quot;base64&quot; string through json. I need to decode and download a file on the client side.
  I have presented the code in a simplified form, leaving what is relevant to the question.</p>
  <p>Here is the route on the express server:</p>
  <pre><code>let xlsx = require('node-xlsx').default;
  const express = require('express');
  const router = express.Router();
  
  router.get('/', (req, res) =&gt; {
    const data = [[1, 2, 3], ['a', 'b', 'c']];
    var buffer = xlsx.build([{ name: &quot;mySheetName&quot;, data: data }])
      .toString('base64');
    res.json(buffer);
  });
  
  module.exports = router;
  </code></pre>
  <p>React component on the client:</p>
  <pre><code>import React, { useEffect } from 'react';
  import axios from 'axios';
  
  const First = () =&gt; {
    useEffect(() =&gt; {
      axios({
        url: 'http://localhost:5000/excel',
        method: 'GET',
        responseType: 'blob',
      }).then(res =&gt; {
        const url = window.URL.createObjectURL(new Blob([res.data]));
        const link = document.createElement('a');
        link.href = url;
        link.setAttribute('download', 'data.xlsx');
        document.body.appendChild(link);
        link.click();
      });
    }, []);
    return (
      &lt;div&gt;
        &lt;h3&gt;First page&lt;/h3&gt;
        &lt;hr className=&quot;gold&quot; /&gt;
      &lt;/div&gt;
    );
  };
  
  export default First;
  </code></pre>
  <p>Regards.</p>