Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active July 1, 2025 11:44
Show Gist options
  • Save GroupDocsGists/50ed72ca7a18fbedde35488a2652fd3a to your computer and use it in GitHub Desktop.
Save GroupDocsGists/50ed72ca7a18fbedde35488a2652fd3a to your computer and use it in GitHub Desktop.
How to merge Word documents in Node.js

Merge Word Documents in Node.js

If you need to merge Word documents, this example shows how, complete with commentary and best practices to help you accomplish your document management tasks effectively. This guide covers the essentials of using Node.js to operate with various file formats, including DOCX and DOC.

πŸ“¦ Prerequisites

  • Install the GroupDocs.Merger package in your Node.js environment.
  • Activate your GroupDocs license key to utilize all features without restrictions.
  • You can get a free trial of GroupDocs.Merger and use a temporary license for unlimited access to our library.
  • This works seamlessly for DOCX and DOC files.

🧩 Key Capabilities

  • Combine multiple Word documents into a single file with ease.
  • Integrate compliance standards while merging to ensure document integrity.
  • Simplify the document management process across different formats.
  • Save merged documents in various file types for versatile usage.
  • Enable flexibility in document structure and formatting during the merging process.

πŸ’» Code Examples

See the following example 1: mergeDocx.js

See the following example 2: mergeWordDocumentsWithPredefinedComplianceMode.js

βœ… How to Use in Node.js

  1. Install the GroupDocs.Merger package via npm to access its functionalities for merging files.
  2. Load your Word documents (mostly in DOCX format) into your application using the merger class.
  3. Utilize the joining method to combine multiple documents easily into one file.
  4. Specify output configurations to define where to save the merged file and in what format.
  5. Execute and save the resulting document, which can also be converted into other formats like DOC if needed.

πŸ“Ž Related Resources

πŸ“œ Final Thoughts

By following these instructions, you can seamlessly merge Word documents and manage your file-format needs effectively. For more details, visit our full docs or request a trial license to explore additional functionalities, including merging files into formats like DOC or DOCX. You'll find the flexibility and power you need to manage documents adeptly!

/*
* This example demonstrates how to merge multiple docx files into single file.
*/
async function mergeDocx(groupdocs, inputFilePath) {
const merger = new groupdocs.merger.Merger(inputFilePath)
const outputPath = `${groupdocs.outputFolder}/MergeDocx.docx`
console.log(`Merged to ${outputPath}`)
merger.join(inputFilePath)
return merger.save(outputPath)
}
module.exports = mergeDocx
/*
* This example demonstrates how merge Word documents with pre-defined Compliance mode into single file.
*/
async function mergeWordDocumentsWithPredefinedComplianceMode(groupdocs, inputFilePath) {
const merger = new groupdocs.merger.Merger(inputFilePath)
const outputPath = `${groupdocs.outputFolder}/MergeWordDocumentsWithPredefinedComplianceMode.docx`
console.log(`Merged to ${outputPath}`)
const wordJoinOptionsCompliance = groupdocs.merger.WordJoinCompliance.Iso29500_2008_Strict
const wordJoinOptions = new groupdocs.merger.WordJoinOptions()
wordJoinOptions.Compliance = wordJoinOptionsCompliance
merger.join(inputFilePath)
return merger.save(outputPath)
}
module.exports = mergeWordDocumentsWithPredefinedComplianceMode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment