How to Validate a Domain Name in Node.js

Cloudmersive
1 min readDec 12, 2022

--

Validating a domain name simply entails contacting DNS services to verify its existence. Thankfully, you can accomplish that in a single API call using the Node.js code examples supplied below in this article. You’ll just need to provide the domain name you wish to validate as a string; after that, simply authenticate the API service with a free-tier Cloudmersive API key (you can get one by registering a free account on our website), and you’re all done.

First run this command to install the SDK:

npm install cloudmersive-validate-api-client --save

Or, alternatively, copy this snippet & add it to your package.json:

  "dependencies": {
"cloudmersive-validate-api-client": "^1.3.9"
}

After that, run the below code (with domain name & key included), and you’re all done:

// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';



var apiInstance = new CloudmersiveValidateApiClient.DomainApi();

var domain = "domain_example"; // String | Domain name to check, for example \"cloudmersive.com\". The input is a string so be sure to enclose it in double-quotes.


var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.domainCheck(domain, callback);

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet