How can I extract images from Word file(doc, docx) with Javascript

I am trying to extract contents from Word file with Node.js and I have already got text with mammoth.
But the image extraction doesn’t work well.
How can I complete it?
I am working on Node.js.

 mammoth.extractRawText({ path: req.file.path })
  .then(async (result) => {
        const images = result.messages.filter(message => message.type === "image");
            images.forEach((image, index) => {
                const { contentType, content } = image;
                const extension = contentType.split("/")[1];
                fs.writeFileSync(`image_${index}.${extension}`, content, 'binary');
            });
       }
    )