Unparalleled suite of productivity-boosting Web APIs & cloud-based micro-service applications for developers and companies of any size.

APIJavascript

How To Detect Any Device And OS In Real-Time With Node.js

How To Detect Any Device And OS In Real-Time With Node.js

What is userstack API?

The userstack API is a real-time, easy-to-use REST API interface capable of parsing User-Agent strings to precisely detect device, browser, and operating system information. 

Implementing the JSON/XML API in your frontend or backend system will give you all the tools you need to take control of your website’s or application’s user experience and the customer journey that goes with it. This API can also be combined with a geolocation api.

Why UserStack API?

UserStack API stands out because of these features:

  • Powerful & Scalable – No need to worry about sending hundreds of thousands of API requests
  • Accurate Data – Highest reliability and accuracy
  • Easy Integration – Powerful API with easy to integrate design
  • Cost-effective – You can start using userstack API for free with 10,000 monthly requests

How to use UserStack API?

Just head over and sign up for a free account, and you will get your free API access key. With your uniquely generated API access key you can start using the UserStack API from anywhere.

Here is a sample of an API request with the access_key parameter.

And here is the result of the request:

  • Operating System 
    • Name of the OS
    • Code of the OS
    • and more
  • Device
    • Flag for mobile device
    • Type – e.g: Desktop
    • Device Code
    • and more
  • Browser
    • Name of the browser
    • Browser engine
    • Browser version
  • And other information about the user

How to do a Bulk User-Agent Lookup?

If you want to check multiple User-Agent strings, you can use the base endpoint with the ua_batch parameter that contains the User-Agent strings to process.

Here is an example of executing a Bulk-User-Agent request:

Specify Response Fields

When you make a bulk lookup, the response can be large. It is usually better to specify your response fields for only the data you need.

Here is how to configure your response fields:

How do I integrate userstack API into the Node.js web app?

In this demonstration, we will create a Node.js web app that integrates the UserStack API. 

How to set up Node.js with UserStack API?

Open your terminal, PowerShell or Bash. Next, type these commands to create a folder and initialize the basic project files.

Then go back to your terminal and type this command to install the required node modules.

Now in this part, copy the static (CSS, js, images) files from our repository. Here is our project file structure:

Next,  install nodemon. nodemon is a tool that helps you develop NodeJS-based applications by automatically restarting the node application when file changes are detected. It improves your productivity.

You can follow these steps to configure nodemon.

Now, go back to your code editor and enter this code:

Here is our final result. Check out the full source code here. 

Hope you liked this demonstration!

Head over now and get your free subscription plan on UserStack

Related posts
APICurrencyFinance

Currency Exchange Rate API: Key Trends for the Coming Years

APIAviation Data

The Role of APIs in Modernizing the Aviation Industry

APIFinancestock data

What to Expect: Financial Data API Trends for the Next Few Years

API

Introducing APILayer's Platinum Support: Elevate Your API Experience

Leave a Reply

Your email address will not be published. Required fields are marked *