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

Cloudmersive
1 min readApr 23, 2020

--

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!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet