How to apply an HTML Template in Node.JS

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.

Image for post
Image for post

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store