How to create a Web-Based Document Viewer in Node.JS

1 min readApr 20, 2020


Today’s tutorial covers the creation of a web-based viewer for a variety of document types, including PDF, DOCX, XLSX, and other Office formats. In order to achieve this within a reasonable timeframe, we will be using an API, which will allow us to finish quite rapidly indeed. Here’s the general process.

First comes our API client setup, which uses this command here for npm install.

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

With our client installed, now we can call viewerToolsCreateSimple:

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.ViewerToolsApi();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.viewerToolsCreateSimple(inputFile, callback);

Now you can enter a document and the API will return an HTML-based embed code for your viewer. Done!




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

Recommended from Medium


See more recommendations