How to get the gender of a first name in Node.js?
1 min readMay 18, 2019
First, we need to add a reference to the library in our packages file:
"dependencies": {
"cloudmersive-validate-api-client": "^1.1.2"
}
Next up, we need to import the package:
var CloudmersiveValidateApiClient = require('cloudmersive-validate-api-client');
Finally, we just need to call the nameGetGender function:
var CloudmersiveValidateApiClient = require('cloudmersive-validate-api-client');
var defaultClient = CloudmersiveValidateApiClient.ApiClient.instance;// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';var apiInstance = new CloudmersiveValidateApiClient.NameApi();var input = new CloudmersiveValidateApiClient.GetGenderRequest(); // GetGenderRequest | Gender request informationvar callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.nameGetGender(input, callback);
That’s it! Let’s try out this input:
{
"FirstName": "Elvira",
"CountryCode": "US"
}
Sure enough, here is the output:
{
"Successful": true,
"Gender": "Female"
}
We can input various input first names as well as the CountryCode if available to help narrow in on the context.