How to get the gender of a first name in Node.js?

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.

Written by

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

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