How to apply an HTML Template in Node.JS
1 min readApr 12, 2020
HTML templates can be a very powerful tool in the right hands. Today we will show you how to implement HTML templates from within Node.JS. Ease-of-use is the name of the game, so we are going to use an API to speed us along. Let’s look at it.
Begin by installing our API client, easy enough with this reference for package.json.
"dependencies": {
"cloudmersive-convert-api-client": "^2.1.6"
}
Next is convertTemplateApplyHtmlTemplate:
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.ConvertTemplateApi();var value = new CloudmersiveConvertApiClient.HtmlTemplateApplicationRequest(); // HtmlTemplateApplicationRequest | Operations to apply to templatevar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.convertTemplateApplyHtmlTemplate(value, callback);
OK, we are already finished with the setup process. Now just input your template and you are good to go. Easy-peasy.