New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

docx-mergex

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

docx-mergex

Merge .docx files with formatting preserved (pure Node.js)

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

📦 docx-mergex

Merge multiple .docx files into one — with formatting preserved — using pure Node.js. No Python. No LibreOffice. Just ZIP-level OpenXML parsing and reassembly.

✅ Features

  • 🔒 Full formatting preserved: styles, bold, lists, paragraphs, tables
  • ⚡ No external deps: pure Node.js (no Python or LibreOffice)
  • 🖥️ Cross-platform: macOS, Linux, and Windows
  • 🛠️ CLI & API: use from the command line or in your code
  • 🔄 Safe merge: keeps metadata, stylesheets, and zip structure untouched
  • 🧪 CI/CD-ready: perfect for templating pipelines and bulk automation

🚀 CLI Usage

npx docx-mergex <input-folder> [output.docx]
  • <input-folder>: directory containing your .docx files
  • [output.docx]: (optional) output filename (defaults to merged.docx)

Example:

npx docx-mergex ./my-docx-folder merged.docx

Files are merged in alphabetical order by filename.

📚 Programmatic API

const mergeDocx = require("docx-mergex");

mergeDocx("./docs", "combined.docx")
  .then(() => console.log("✅ Merge complete"))
  .catch(err => console.error("❌ Merge failed:", err));
  • ./docs: folder containing .docx files
  • "combined.docx": desired output path

⚠️ Limitations

  • Only word/document.xml contents are merged — headers, footers, and numbering beyond the body are not preserved
  • No page/section breaks are inserted by default (coming soon)
  • Input files must be valid .docx (e.g. Word exports, Google Docs exports)
  • Non-.docx files and hidden folders are skipped silently

❌ Common Errors

ErrorCauseSolution
EISDIR: illegal operation on directoryOutput path is a directory, not a fileProvide a valid .docx filename
The XML document isn’t in Word formatMerged XML is malformed or ZIP structure brokenEnsure input docs are valid; update module
No .docx files foundInput folder contains no .docx filesCheck folder path and file extension

🧪 Testing Locally

  • Link the module (from its folder):

    npm link
    
  • In your test folder, link it in:

    npm link docx-mergex
    
  • Prepare sample docs:

    mkdir test-docs
    cp ~/Downloads/*.docx test-docs/
    
  • Run the CLI:

    docx-mergex ./test-docs merged.docx
    
  • Verify in Microsoft Word or LibreOffice.

  • To unlink after testing:

    # In test folder
    npm unlink docx-mergex
    
    # In module folder
    npm unlink
    

🤖 Roadmap / Coming Soon

  • Insert section/page breaks between merged documents
  • Merge headers, footers, and numbering
  • Recursive merging from nested folders
  • Option to insert filename as heading before each document
  • CLI flag for custom merge order

👥 Contributing

We welcome contributions!

  • Fork this repo

  • Run npm install

  • Make your changes (add features, fix bugs)

  • Test via:

    node bin/cli.js <input> <output>
    
  • Submit a Pull Request with a clear description of your changes

📄 License

MIT © 2025 Huzaifa Azim

Keywords

docx

FAQs

Package last updated on 07 Jul 2025

Did you know?

Socket

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.

Install

Related posts