How to Identify Robots in Node.JS

Cloudmersive
Sep 24, 2020 · 2 min read

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.

Image for post
Image for post

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

Written by

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

The Startup

Medium's largest active publication, followed by +752K people. Follow to join our community.

Cloudmersive

Written by

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

The Startup

Medium's largest active publication, followed by +752K people. Follow to join our community.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

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