How to Merge HTML Files in Node.js
Documents saved in HTML format can be viewed on any browser, which places HTML among the more convenient, interoperable file types around. With multiple HTML files in hand — especially those containing related contents — you can further increase the efficiency of this file type by programmatically combining related contents into a single, ‘vertically’ stacked HTML file. This operation can be accomplished in just a few steps with the Node.js code examples provided below; using these examples will call our “Merge Two HTML Files” API, and you can use it for free by registering a free account on our website (this provides a free-tier API key with a limit of 800 API calls per month).
To begin your API call, start by running the below command to install the Node.js SDK:
npm install cloudmersive-convert-api-client --save
Next up, use the below code to call the function, including your HTML files sequentially in the var inputFile1 and var inputFile2 parameters (your API key goes in the Apikey.apiKey field):
var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');
var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveConvertApiClient.MergeDocumentApi();
var inputFile1 = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // File | First input file to perform the operation on.
var inputFile2 = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // 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.mergeDocumentHtml(inputFile1, inputFile2, callback);
That’s all you need to do — no more code required!