How to validate a Word DOCX Document in Node.JS

Cloudmersive
2 min readApr 12, 2020

--

A simple document validation system will save you from the heap of issues that can be brought on down the line by invalid files. I’m going to guess that you would rather get this over with as soon as possible, given the somewhat dry nature of the subject matter. Well, you are in luck, as we will be making good use of an API to speed through our process.

First step: installation. Using npm install, this is very quick.

npm install cloudmersive-convert-api-client --save

After that’s done with, it’s time to call validateDocumentDocxValidation.

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.ValidateDocumentApi();var inputFile = "/path/to/file"; // File | Input file to perform the operation on.var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.validateDocumentDocxValidation(inputFile, callback);

Finally, just input a DOCX file to test it out. You will be told whether or not the file is valid, and if not, what sort of errors might be present. Done.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet