How to compare two Microsoft Word DOCX Files in Node.JS

Our mission on this fine day is a simple one — we need to create a system for comparing DOCX files with one another using Node.JS. Let’s get to it.

We begin by adding this reference to our package.json file.

"dependencies": {
"cloudmersive-convert-api-client": "^2.1.6"
}

That will install our API client and open up compareDocumentDocx for calling:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.CompareDocumentApi();var inputFile1 = "/path/to/file"; // File | First input file to perform the operation on.var inputFile2 = "/path/to/file"; // File | Second input file to perform the operation on (more than 2 can be supplied).var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.compareDocumentDocx(inputFile1, inputFile2, callback);

Finally, enter your two DOCX files (or more than two) and the API will make the comparison, highlighting any and all differences between them. So easy!

Image for post
Image for post

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store