How to fully validate a URL in Node.JS

Cloudmersive
2 min readMar 24, 2020

--

URL validation can be used for all sorts of excellent applications, such as guarding against broken links or to aid in filtering spam user submissions. Regardless of how you will use it, we are going to dive into how to perform this task using Node.JS.

Begin by using npm install on our API client.

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

With that out of the way, proceed with calling the URL validation function from the client:

var CloudmersiveValidateApiClient = require('cloudmersive-validate-api-client');var defaultClient = CloudmersiveValidateApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveValidateApiClient.DomainApi();var request = new CloudmersiveValidateApiClient.ValidateUrlRequestFull(); // ValidateUrlRequestFull | Input URL requestvar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.domainUrlFull(request, callback);

All that is left to do now is enter your URL and test it out. This API will not only check the syntax of the URL, but also check that it exists, check the endpoint, and scan for viruses. All in all, a great way to vet your links!

--

--

Cloudmersive

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