Set the Language Code of an HTML Document in Node.JS

Cloudmersive
2 min readJul 8, 2021

The language code within an HTML document allows search engines to identify the language of a web page and determine the proper search results for users. The codes themselves contain only two letters that declare the corresponding language, such as ‘en’ for English or ‘ja’ for Japanese. By utilizing the following API in Node.JS, you will be able to automatically set the language code of an HTML document with no additional hassle.

To begin, you will 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"
}

Next, you can simply input your file or file URL, along with the two-letter language code you want to set into 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 languageCode = "languageCode_example"; // String | The HTML langauge code to set.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.editHtmlHtmlSetLanguage(languageCode, opts, callback);

And just like that, your language code will be set for the web page.

--

--

Cloudmersive

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