How to detect the language of a string in Node.js

Let’s say we have a text string, and we want to automatically detect the language of this string in Node.js. This is pretty easy to do. First, we need to add a reference to the library in Node.js:

"dependencies": {
"cloudmersive-nlp-api-client": "^1.1.2"

Now, all we need to do is call the method languageDetectionPost:

var CloudmersiveNlpApiClient = require('cloudmersive-nlp-api-client');
var defaultClient = CloudmersiveNlpApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveNlpApiClient.LanguageDetectionApi();var textToDetect = "textToDetect_example"; // String | Text to detect language ofvar callback = function(error, data, response) {
if (error) {
} else {
console.log('API called successfully. Returned data: ' + data);
apiInstance.languageDetectionPost(textToDetect, callback);

This will automatically identify the language of the input string. Support includes Danish (DAN), German (DEU), English (ENG), French (FRA), Italian (ITA), Japanese (JPN), Korean (KOR), Dutch (NLD), Norwegian (NOR), Portuguese (POR), Russian (RUS), Spanish (SPA), Swedish (SWE), Chinese (ZHO).

Other Natural Language Processing APIs are also available in the same library, including the ability to identify nouns, verbs, adjectives, to do semantic processing and so on.

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