docx

Generate and modify Microsoft Word .docx files with a declarative JS/TS API in Node or the browser.

Library
npm
v9.8.0
5,917 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
92 /100 Excellent
Development Activity 100
Maintenance 96
Community 72
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
79 /100 Good
Architecture 80
Code Quality 84
Innovation 74
Learning Curve 78

docx is a JavaScript/TypeScript library for programmatically generating and modifying Microsoft Word (.docx / OOXML) documents, running identically in Node.js and the browser. Instead of hand-assembling OOXML XML, developers compose documents from typed building blocks — Document, Paragraph, TextRun, Table, headers/footers, images, and more — and hand the result to Packer to produce a real .docx file.

Beyond basic document creation, docx supports advanced Word features such as styles, numbering, tables of contents, footnotes, comments, and a document patcher for editing existing .docx templates in place. With 5,800+ GitHub stars, 146 contributors, and active maintenance, it is the de facto standard for Word document generation in the JavaScript ecosystem, used for everything from invoice generation to reporting pipelines.

What You Get

  • A declarative document model (Document, Paragraph, TextRun, Table, ImageRun, headers/footers) that maps closely to how Word documents are structured
  • Isomorphic support — the same API runs in Node.js and directly in the browser without a native dependency
  • Rich formatting support: styles, numbering/bullets, tables of contents, footnotes, comments, page breaks, and sections
  • A Packer utility to serialize documents to Buffer, Blob, base64, or stream depending on the target environment
  • A document patcher (patchDocument) for modifying fields inside an existing .docx template without rebuilding it from scratch
  • Full TypeScript typings and extensive docs/demo scripts covering common document-construction patterns

Common Use Cases

  • Generating invoices, contracts, or reports as downloadable .docx files from a web app or backend service
  • Building document-automation pipelines that merge data into Word templates (e.g. certificates, letters, statements)
  • Producing .docx exports as an alternative to PDF from reporting or CMS-style applications
  • Patching specific fields or placeholders inside existing Word templates without regenerating the whole document

Under The Hood

Architecture - The library models a Word document as a tree of typed classes under src/file (Document/File, Paragraph, TextRun, Table, sections, headers/footers, numbering, styles), each of which knows how to render itself to OOXML XML. src/export contains the Packer, which walks the document tree, serializes each part to its corresponding XML file, and zips them into the final .docx (a .docx is itself a ZIP of XML parts per the OOXML spec). A separate src/patcher module implements string/placeholder-based patching of an existing .docx’s XML parts, letting callers modify a template without reconstructing the whole tree.

Tech Stack - Written in TypeScript, built and bundled with Vite into dual ESM/CJS output plus type declarations, and tested with Vitest (including a coverage/UI mode). It ships as a pure JS/TS package with no native bindings, which is what allows it to run unmodified in both Node and browser bundlers.

Code Quality - The src tree includes 196 *.spec.ts files, giving dense unit coverage across nearly every document-model class (paragraphs, tables, styles, numbering, patcher, etc.). Code is organized by OOXML concern (file/, export/, patcher/, util/) with consistent naming that mirrors Word’s own terminology, ESLint and Prettier enforce style, and cspell checks catch documentation typos — indicating a maintained, quality-conscious codebase rather than a one-off generator.

API Design - The class-based, declarative API (new Document({ sections: [{ children: [new Paragraph(...)] }] })) closely tracks how a Word document is conceptually structured, which makes the learning curve shallow for anyone who has used Word. Extensive docs (a docsify site under docs/), a demo/ directory with runnable examples for dozens of features, and full TypeScript types substantially lower the boilerplate needed to produce a first working document.

Used by 5 apps in this directory

TypeScript
95%
Apache 2.0

AionUi

AI Agents · Productivity

33,179

Free, open-source Cowork desktop app that unifies Claude Code, Codex, Gemini CLI, and 20+ AI agents into a single platform with multi-agent teams, 24/7 cron automation, and zero-config built-in agent.

View details
85
Repo Health
76
Technical
66
Dependency
Built with
TypeScript 95%
Updated 3 weeks ago
JavaScript
95%
MIT

AnythingLLM

AI Assistants · Automation · Developer Tools

66,533

The all-in-one AI platform for private document chat, no-code agents, and local LLMs with zero setup friction.

View details
90
Repo Health
78
Technical
64
Dependency
Built with
JavaScript 95%
Updated 6 days ago
TypeScript
99%
AGPL 3.0

Cherry Studio

AI Assistants

52,202

All-in-one AI desktop client with 300+ assistants and multi-model support

View details
89
Repo Health
84
Technical
70
Dependency
Built with
TypeScript 99%
Updated 4 days ago
TypeScript
95%
AGPL 3.0

Docmost

CMS · Collaboration · Note Taking

21,801

Self-hosted collaborative wiki and knowledge base with real-time editing, diagrams, AI assistance, and enterprise access controls — a modern alternative to Confluence and Notion.

View details
89
Repo Health
70
Technical
69
Dependency
Built with
TypeScript 95%
Updated 5 days ago
TypeScript
44%
Other

Magic

AI Agents · Automation · Low Code Platforms

5,043

Magic is an enterprise-grade open-source AI agent platform combining a generalist AI agent, workflow engine, IM, and collaborative office system for running an AI-powered digital workforce.

View details
70
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 44%
PHP 32%
Updated 1 months ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers