Get the Language Code for an HTML Document in Node.JS
In the previous article, we demonstrated how you can set the language of an HTML document by using an API in Node.JS. However, what if you need to retrieve the language code instead of setting it? Well, lucky for you, we have an API for that as well. This can be completed in less than a minute and will save you a good amount of time if you have multiple documents/web pages you need to perform the operation on.
First, we will run this command to install the SDK:
npm install cloudmersive-convert-api-client --save
Or, we can this snippet to our package.json:
"dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}
Once the installation is complete, we can call the function with the following 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 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.editHtmlHtmlGetSitemap(opts, callback);
The sitemap URL for the input HTML file will be delivered promptly. To retrieve your API key, visit the Cloudmersive website and register for a free account; this will provide 800 monthly calls across any of our APIs.