title: Node.js - How to get remote audio file's duration?
body: <p>I have a binaries storage bucket (in Firebase Storage) and I am implementing a node.js Cloud Function which gets an audio (audio/m4a or audio/caf), verifies it format and duration, and then associate its uri with a document in my database (or deletes the audio file if its duration is not valid).</p>
  <p>Before creating the document in my database, I need to validate the audio file.</p>
  <p>For downloading the files from the storage I am using this function:</p>
  <pre><code>exports.downloadBinaryFileFromUrl = function (fileUrl) {
    /* This function downloads a binary-encoded file from its URL and returns it */
    return axios
      .get(fileUrl, {
        responseType: &quot;arraybuffer&quot;,
      })
      .then((res) =&gt; Buffer.from(res.data, &quot;binary&quot;))
      .catch((err) =&gt; {
        if (err.response) {
          /* 
            The request was made and the server responded with a status code
            that falls out of the range of 2xx
          */
          throw err.response.data;
        } else if (err.request) {
          // Client never received a response, or request never left
          throw err.request;
        } else {
          // Something happened in setting up the request that triggered an Error
          throw new Error(`Error: ${err.message}`);
        }
      });
  };
  </code></pre>
  <p>Any ideas how to get the audio file's duration using Node.js?</p>