How can I use JavaScript to take content from a textarea and print it to a docx file?

I am trying to make a html to take something I have typed in the textarea and print in out in a docx file. Any ideas?

I tried a library DOCX but couldn’t get my hand around it. And I also tried mammoth.js.

import { Document, Packer } from "docx";

function saveToDocx() {
  var content = document.getElementById("content").value;

  // Create a new document
  const doc = new Document();
  doc.addParagraph(content);

  // Generate the DOCX file
  Packer.toBlob(doc).then((blob) => {
    // Create a temporary link to download the DOCX file
    var link = document.createElement("a");
    link.href = URL.createObjectURL(blob);
    link.download = "output.docx";
    link.click();
  });
}