Append an HTML Tag to the HEAD of an HTML Doc in Node.JS

Cloudmersive
2 min readJul 8, 2021

The HTML tag represents the root of an HTML document, so if your document is missing it, it’s kind of a big deal. To ensure that your HTML documents include an HTML tag, you can use the following API in Node.JS to append it to the HEAD of an HTML document.

The first step is to run this command to install the SDK:

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

Or, you can add this snippet to your package.json:

"dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}

After the installation, you can call the function with the below example code:

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.EditHtmlApi();var htmlTag = "htmlTag_example"; // String | The HTML tag to append.var opts = {
'inputFile': Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer), // File | Optional: Input file to perform the operation on.
'inputFileUrl': "inputFileUrl_example" // String | Optional: URL of a file to operate on as input.
};
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.editHtmlHtmlAppendHeaderTag(htmlTag, opts, callback);

With this simple process, your HTML tag will be set in its respective place at the head of the document.

--

--

Cloudmersive

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