
Security News
PolinRider: North Korea-Linked Supply Chain Campaign Expands Across Open Source Ecosystems
PolinRider expands across npm, Packagist, Go modules, and Chrome extensions, using hidden loaders to target developer environments.
@office-open/docx
Advanced tools
Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.
Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.
# Install with npm
$ npm install @office-open/docx
# Install with pnpm
$ pnpm add @office-open/docx
import { Document, Paragraph, TextRun, Packer } from "@office-open/docx";
import { writeFileSync } from "node:fs";
const doc = new Document({
sections: [
{
children: [
new Paragraph({
children: [
new TextRun("Hello World"),
new TextRun({
text: " - Bold text",
bold: true,
}),
],
}),
],
},
],
});
const buffer = await Packer.toBuffer(doc);
writeFileSync("My Document.docx", buffer);
Check the demo folder for 100+ working examples covering every feature.
Performance comparison against original docx (9.6.1) package (higher ops/s is better, Windows 11 / Node 24).
Default = XML DEFLATE level 1 (SuperFast, matching MS Office) + media STORE. All STORE = no compression ({ compression: { xml: 0 } }). docx (async) always uses DEFLATE for ALL entries including images (via JSZip, hardcoded, no STORE option).
// Default (matches MS Office)
await Packer.toBuffer(doc);
// All STORE (no compression)
await Packer.toBuffer(doc, { compression: { xml: 0 } });
Create + toBuffer (end-to-end)
| Scenario | Default sync | Default async | All STORE sync | All STORE async | docx |
|---|---|---|---|---|---|
| Simple (2p + 1 img) | 174 ops/s | 155 ops/s | 202 ops/s | 203 ops/s | 82 ops/s |
| Styled paragraphs (20) + 1 img | 179 ops/s | 146 ops/s | 198 ops/s | 198 ops/s | 86 ops/s |
| Table (10x5) | 949 ops/s | 565 ops/s | 1,830 ops/s | 1,867 ops/s | 190 ops/s |
| Full featured + 2 imgs | 94 ops/s | 89 ops/s | 102 ops/s | 100 ops/s | 57 ops/s |
Large Files — Create + toBuffer
| Scenario | Default sync | Default async | All STORE sync | All STORE async | docx |
|---|---|---|---|---|---|
| 2000 paragraphs + 20 images | 4.68 ops/s | 3.13 ops/s | 3.50 ops/s | 3.08 ops/s | 2.07 ops/s |
| 200x10 table | 64.9 ops/s | 62.6 ops/s | 69.7 ops/s | 72.6 ops/s | 19.5 ops/s |
| 20 sections x 100p + 40 images | 1.58 ops/s | 1.69 ops/s | 1.79 ops/s | 1.65 ops/s | 1.16 ops/s |
Large File (~100MB) — Mixed Content
500 styled paragraphs + 38 mixed-size images (1-5MB, 100MB total) + 50x10 table. Speedup is vs docx.
| Method | Speed | Speedup |
|---|---|---|
| All STORE | 0.42 ops/s | 1.4x |
| Default | 0.31 ops/s | 1.1x |
| docx | 0.29 ops/s |
FAQs
Generate, parse, and patch .docx documents with a declarative TypeScript API
The npm package @office-open/docx receives a total of 2,032 weekly downloads. As such, @office-open/docx popularity was classified as popular.
We found that @office-open/docx demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
PolinRider expands across npm, Packagist, Go modules, and Chrome extensions, using hidden loaders to target developer environments.

Security News
Open source attacks are accelerating as AI coding agents pull in dependencies faster, with less human review.

Research
/Security News
Malicious Chrome and Firefox extensions posed as free VPNs while stealing clipboard data through later extension updates.