JavaScript Word document libraries

Updated Nov 2026

JavaScript Word document libraries read, create, and fill in .docx files from code. A template library fills placeholders in a document authored in Word rather than building each paragraph in code. These libraries generate the contracts, invoices, and reports that apps export as Word files.

Popularity

Mammoth has the most monthly downloads in this comparison, at 59.9M.

LibraryMonthly downloadsStarsLast releaseLicense
Mammoth
59.9M
6.3KSep 2026BSD-2-Clause
docx
43.4M
6.0KNov 2026MIT
docx-preview
14.4M
2.2KSep 2026Apache-2.0
Docxtemplater
6.5M
3.7KOct 2026MIT
html-to-docx
1.2M
484Mar 2023MIT
@turbodocx/html-to-docx
1.0M
234Oct 2026MIT
docx-templates
555.7K
1.1KDec 2025MIT
easy-template-x
233.8K
537Nov 2026MIT
Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Converts Word content into semantic HTML or extracts plain text for indexing and processing.

Downloads / mo
59.9M
Stars
6.3K
Last release
1.13.0
License
BSD-2-Clause

Strengths

  • Extracts text for downstream processing. extractRawText returns document text without formatting.
  • Maps Word styles into HTML. Map named paragraph styles to headings and other HTML elements.

Limitations

  • Table borders are discarded. Table content survives conversion, while table border formatting is ignored.
  • Untrusted HTML needs separate sanitization. Sanitize converted content before embedding it into a website.

Quickstart

From README.md
$ npm install mammoth
var mammoth = require("mammoth");

mammoth.convertToHtml({path: "path/to/document.docx"})
    .then(function(result){
        var html = result.value; // The generated HTML
        var messages = result.messages; // Any messages, such as warnings during conversion
    })
    .catch(function(error) {
        console.error(error);
    });

Mammoth examples

From open-source projects on GitHub

Generates Word documents in JavaScript or TypeScript for Node.js and browser applications.

Downloads / mo
43.4M
Stars
6.0K
Last release
9.15.4
License
MIT

Strengths

  • Builds rich Word documents. Add tables, images, charts, headers, and footers with the document API.
  • Updates existing Word templates. patchDocument replaces placeholders while preserving the surrounding document structure.
  • Converts rich HTML into content. htmlToContent turns HTML into native Word paragraphs and tables.

Limitations

  • PDF export needs another tool. Generate Word files here, then convert them separately for PDF delivery.
  • HTML images need supplied data. Pass image data explicitly; htmlToContent does not download remote images.

Quickstart

From quickstart.md
$ npm install --save docx
import { Document, Packer, Paragraph, TextRun } from "docx";
import * as fs from "fs";

const doc = new Document({
    sections: [
        {
            // Documents are organized into sections
            children: [
                new Paragraph({
                    children: [new TextRun("Hello World!")],
                }),
            ],
        },
    ],
});

Packer.toBuffer(doc).then((buffer) => {
    fs.writeFileSync("My Document.docx", buffer);
});

docx examples

From open-source projects on GitHub

docx-preview

Renders a Word document into HTML inside a web page, keeping HTML semantics where it can.

Downloads / mo
14.4M
Stars
2.2K
Last release
0.4.1
License
Apache-2.0

Strengths

  • Renders headers and footers. Options turn the rendering of headers, footers, footnotes, and endnotes on or off.

Limitations

  • Limited by what HTML can show. The page renders as HTML rather than as an image of the Word layout.
  • No real-time page breaking. Insert manual page breaks wherever the pages must split.

Quickstart

From README.md
$ npm install docx-preview
<!--lib uses jszip-->
<script src="https://unpkg.com/jszip/dist/jszip.min.js"></script>
<script src="docx-preview.min.js"></script>
<body>
    <div id="container"></div>

<script>

</script>
</body>

Generates documents by replacing placeholders, loops, and conditions inside existing Word templates.

Downloads / mo
6.5M
Stars
3.7K
Last release
3.71.1
License
MIT

Strengths

  • Templates stay editable in Word. Non-programmers can edit the source templates before generation.
  • Repeats sections from structured data. Use loops and conditions to generate repeated or conditional template content.

Limitations

  • Images and HTML need modules. Add paid modules to insert images or formatted HTML.
  • Starts with an existing template. Supply a Word template containing the placeholders to replace.

Quickstart

From Get started docs
$ npm install --save docxtemplater pizzip
const Docxtemplater = require("docxtemplater");
const PizZip = require("pizzip");
const fs = require("fs");
const path = require("path");
const content = fs.readFileSync(
    path.resolve(__dirname, "input.docx"),
    "binary"
);
const zip = new PizZip(content);
const doc = new Docxtemplater(zip, {
    paragraphLoop: true,
    linebreaks: true,
});
doc.render({
    first_name: "John",
    last_name: "Doe",
    phone: "+33666666",
    description: "The Acme Product",
});
const buf = doc.toBuffer();
fs.writeFileSync(path.resolve(__dirname, "output.docx"), buf);

Docxtemplater examples

From open-source projects on GitHub

Converts HTML strings into Word documents with configurable page layout, headers, footers, and tables.

Downloads / mo
1.2M
Stars
484
Last release
1.8.0
License
MIT

Strengths

  • Converts existing HTML into Word. Reuse HTML content as the input for document generation.
  • Adds page numbers to footers. Enable footer page numbers with the pageNumber option.

Limitations

  • Runs outside the browser directly. Use a server-side conversion step for browser applications.
  • Fonts vary between Word processors. LibreOffice and Word Online choose replacement fonts themselves.

Quickstart

From example-node.js
$ npm install html-to-docx file-saver
import HTMLtoDOCX from 'html-to-docx';
import { saveAs } from 'file-saver';

const fileBuffer = await HTMLtoDOCX(htmlString, null, {
  table: { row: { cantSplit: true } },
  footer: true,
  pageNumber: true,
});

saveAs(fileBuffer, 'html-to-docx.docx');

html-to-docx examples

From open-source projects on GitHub

@turbodocx/html-to-docx

Converts HTML into Word documents in Node.js without a headless browser or external binaries.

Downloads / mo
1.0M
Stars
234
Last release
1.23.3
License
MIT

Strengths

  • Actively maintained fork. TurboDocx continues the original html-to-docx project with the help of its contributors.

Limitations

  • SVG conversion needs Node.js. In the browser, SVG images embed natively and need a recent Office release to display.

Quickstart

From README.md
$ npm install @turbodocx/html-to-docx
import HtmlToDocx from "@turbodocx/html-to-docx";

const htmlString = `<!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="UTF-8" />
            <title>Document</title>
        </head>
        <body>
            <h1>Hello world</h1>
        </body>
    </html>`;

const docx = await HtmlToDocx(htmlString);

@turbodocx/html-to-docx examples

From open-source projects on GitHub

docx-templates

Creates reports from Word templates that hold commands, in Node.js or the browser.

Downloads / mo
555.7K
Stars
1.1K
Last release
4.15.0
License
MIT

Strengths

  • Templates run JavaScript. Commands in the template run JavaScript and insert its results into the document.
  • Repeats table rows. FOR and END-FOR commands repeat content for each item, including table rows.

Limitations

  • Template code runs untranspiled. Write template code that the target browsers support without a transpiler.

Quickstart

From README.md
$ npm install docx-templates
import createReport from 'docx-templates';
import fs from 'fs';

const template = fs.readFileSync('myTemplate.docx');

const buffer = await createReport({
  template,
  data: {
    name: 'John',
    surname: 'Appleseed',
  },
});

fs.writeFileSync('report.docx', buffer)

easy-template-x

Fills Word templates with data through tags, in Node.js or the browser.

Downloads / mo
233.8K
Stars
537
Last release
8.1.0
License
MIT

Strengths

  • Adds charts, images, and links. Plugins insert images, hyperlinks, charts, and raw XML into a template.
  • Repeats rows and lists. A loop tag repeats text, table rows, table columns, or list items.

Limitations

  • Loops need paired tags. Mark each loop with an opening tag that starts with # and a closing tag that starts with a slash.

Quickstart

From README.md
$ npm install easy-template-x
import * as fs from "fs";
import { TemplateHandler } from "easy-template-x";

// 1. read template file
const templateFile = fs.readFileSync("myTemplate.docx");

// 2. process the template
const data = {
    posts: [
        { author: "Anakin", text: "Luke, I am\nyour father." },
        { author: "Luke", text: "No! That's impossible!" }
    ]
};

const handler = new TemplateHandler();
const doc = await handler.process(templateFile, data);

// 3. save output
fs.writeFileSync("myTemplate - output.docx", doc);

easy-template-x examples

From open-source projects on GitHub

FAQ

docx is a TypeScript and JavaScript library that generates Word documents through a declarative API. It runs in Node.js and in the browser.

docx-preview renders a Word document into HTML inside a web page. Its output follows what HTML can display rather than the exact Word layout.

Docxtemplater generates Word documents from a template by replacing placeholders with data. Its templates support loops and conditions, and people without programming skills can edit them in Word.

Mammoth converts a Word document into HTML built from the document's semantic styles. Its extractRawText function returns the plain text without formatting.

The unscoped html-to-docx package states that direct browser use does not work.

Mammoth ignores formatting of the table itself, including borders.

For coding agents

Found your Word document library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official