How to Validate a Street Address in Node.JS

Our goal today is to set up street address validation from within Node.JS. You probably think this is going to be an irritating slog to accomplish. Ordinarily, you would be correct, but not today. We are going to zip straight to the finish line in record time using an API designed for the task.

Using this dependency reference in your package.json, install the API client for validation.

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

Following that, call the street address validation function:

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.AddressApi();var input = new CloudmersiveValidateApiClient.ValidateAddressRequest(); // ValidateAddressRequest | Input parse requestvar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.addressValidateAddress(input, callback);

And it’s just that easy. Enter in your test address and try it out! You will be returned the validity of said address, plus the latitude and longitude.

Image for post
Image for post

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