How to Identify Robots in Node.JS

Cloudmersive
The Startup
Published in
2 min readSep 24, 2020

Your website should always be optimized for user interface, and understanding the operating systems and devices with which your content is being accessed will help you improve a user’s experience as well as the overall accessibility of your site. The following API will allow you to parse the user-agent header for any user and determine first if they are a robot including their bot URL, and then what OS, device, and browser is being used to access your website.

First, we need to install the SDK:

npm install cloudmersive-validate-api-client –save

Alternately, you can add this snippet to your package.json:

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

Then, we can call our function, UserAgentParse:

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

Now, you can ensure the best online experience for your clients and track any bot usage. You can receive your API Key on the Cloudmersive website. This will give you access to 800 free monthly calls across our library of APIs.

--

--

Cloudmersive
The Startup

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