Use our JavaScript file difference checker, compare two documents and see the differences between them clearly shown in the output. You no longer need to compare your documents manually. Also note that the comparison result can be exported to a DOCX, PDF, DOC and others.
Our Node solution is designed to give you the best possible results when using a complex comparison algorithm. So, you no longer need to manually look up differences in documents – feel free to use our API to diff two files.
Our comparison engine looks for differences at the level of characters or whole words. And if only one character was changed, the whole word will be highlighted as changed. All found changes can be clearly viewed in the output and exported in a convenient format.
The most popular types of comparison are comparing PDF and Word files. Therefore, we will learn our Node diff tool and its comparison function using these examples.
Sometimes you need to make sure that your PDF document has not been modified and compare it with the original version. Or you already know that your PDF has really changed, and you need to look where and how. Then you can compare two versions of PDF files and see the differences. And to avoid doing it manually, just use our Node diff checker API.
With our Node solution, you will see even small changes that you could easily miss in a manual comparison.
Word documents are fairly easy to change, so it is important to compare Word files to make sure parts or the entire document have not changed.
To compare Word files, use our Node solution, just like with PDF. You can do this in the example below.
To see how our Node document compare works, load two files you want to compare and choose an export file format.
After the comparison is completed, the document with the diff will be automatically downloaded in the format you selected.
It is important that the documents being compared must not have any revisions before the comparison, so we need to accept all revisions before the compare starts. Do not worry, we have taken care of that in our example:
import * as fs from "fs";
const wordsApi = new WordsApi("####-####-####-####-####", "##################");
const fileName1 = "Input1.docx";
const fileName2 = "Input2.docx";
const fileResult = "Output.docx";
// Upload documents to cloud storage.
const firstDocumentContent = fs.createReadStream(fileName1);
const uploadFirstFileRequest = new model.UploadFileRequest({
fileContent: firstDocumentContent,
path: fileName1
});
wordsApi.uploadFile(uploadFirstFileRequest)
.then((uploadFirstFileRequestResult) => {
// tslint:disable-next-line:no-console
console.log("Result of UploadFirstFileRequest: ", uploadFirstFileRequestResult);
const secondDocumentContent = fs.createReadStream(fileName2);
const uploadSecondFileRequest = new model.UploadFileRequest({
fileContent: secondDocumentContent,
path: fileName2
});
wordsApi.uploadFile(uploadSecondFileRequest)
.then((uploadSecondFileRequestResult) => {
// tslint:disable-next-line:no-console
console.log("Result of UploadSecondFileRequest: ", uploadSecondFileRequestResult);
// Compare documents in cloud.
const compareDataOptions = new model.CompareData({
author: "author",
fileReference: model.FileReference.fromRemoteFilePath(fileName2)
})
const compareDocumentRequest = new model.CompareDocumentRequest({
name: fileName1,
compareData: compareDataOptions,
destFileName: fileResult
});
wordsApi.compareDocument(compareDocumentRequest)
.then((compareDocumentRequestResult) => {
// tslint:disable-next-line:no-console
console.log("Result of CompareDocumentRequest: ", compareDocumentRequestResult);
// Download result document from cloud storage.
const downloadFileRequest = new model.DownloadFileRequest({
path: fileResult
});
wordsApi.downloadFile(downloadFileRequest)
.then((downloadFileRequestResult) => {
// tslint:disable-next-line:no-console
console.log("Result of DownloadFileRequest: ", downloadFileRequestResult);
fs.writeFileSync(fileResult, downloadFileRequestResult.body);
});
});
});
});
Install 'Aspose.Words Cloud SDK for Node.js' using NPM package manager. Run npm install asposewordscloud --save from the command line to install the SDK via the NPM package manager. As an alternative, you can manually clone Aspose.Words Cloud SDK for Node.js source code from GitHub and use it in your project. Please follow these Instructions to quickly get the necessary security credentials and access our REST API.
Refer to the Repository Documentation to see more details.