Today we’re announcing that JavaScript developers can easily implement the world’s leading device detection solution utilizing the updated API that now supports Node.js environment. Node.js is available for Enterprise customers deploying DeviceAtlas locally.
Device detection for JavaScript environments
Node.js is a very popular, open-source runtime environment based on JavaScript. It’s a fast-growing solution that has a substantial library of modules available, permitting easy extensibility, as well as an active community helping the solution grow.
For developers applying device detection in their projects, an additional benefit of using Node.js is the reduction of context switching cost for a developer moving between front-end and back-end programming on a project. In other words, with Node.js front-end and back-end languages communication is easier and faster to implement.
Dynamic content delivery
Using our Node.js API a front-end developer can easily leverage DeviceAtlas on the server-side, and thus provide more dynamic content to different visiting devices than can be done on the client-side alone.
The DeviceAtlas device detection API provides a way to detect devices based on HTTP headers. Using the headers, the API returns device information such as device type, screen width, screen height, vendor, model etc. All these device characteristics can be used for content adaptation, redirection, ad targeting, or analytics purposes. Read this article to better understand how device detection works.
Migrate Node.js websites from RWD to RESS
DeviceAtlas now helps organizations using Node.js to migrate their websites from Responsive Web Design to RWD with Server-Side components (RESS). This allows them to deliver richer variation in content according to the visitor profile, while reducing infrastructure costs, ensuring faster page load times (reducing bounce rate for mobile traffic), and lower data costs for end-users.
An additional benefit of using DeviceAtlas Node.js' API is the reduction of context switching cost for a developer moving between front-end and back-end programming on a project.
Deploying DeviceAtlas in a Node.js-based solution
DeviceAtlas deployed locally is based on a device data file that you can update every day, given that our team releases daily file updates. Frequent file updates increase the device detection’s accuracy.
Here's how to create an API call. The following code should be in the main .js file and reused in other parts of the application.
var DeviceApiWeb = require('deviceatlas-deviceapi').DeviceApiWeb;
/* Use the singleton pattern and export so that only 1 instance exists in the application. */
module.exports.deviceApi = (function() {
/* Create an instance of DeviceApiWeb with default config */
var deviceApi = new DeviceApiWeb();
/* Load data. */
try {
deviceApi.loadDataFromFile('path/to/datafile.json');
} catch(e) {
//json could not load! do something!
}
return new deviceApi;
})();
And here is the code sample showing you how to look up properties with DeviceAtlas API in Node.js.
var DeviceApiWeb = require('deviceatlas-deviceapi').DeviceApiWeb;
/* Look up device properties. The detection is done based on the nodejs request object*/
var properties = deviceApi.getPropertiesFromRequest(request);
/* Use the properties - e.g. detect mobile device. */
// if there is a property named "mobileDevice" and the value is true
if (properties.contains('mobileDevice', true)) {
// example 1: Get the screen width for image optimization
var displayWidth = properties.containsKey('displayWidth')?
properties.get('displayWidth').getValue(): 100;
// example 2: Get the device vendor name
var vendor = properties.containsKey('vendor')?
properties.get('vendor').getValue(): '';
// example 3: Touch screen optimization
var useBiggerIcons = properties.contains('touchScreen', true);
// example 4: Send Geo Location JS to client
var supportsGeoLocation = properties.contains('js.geoLocation', true);
}
You can find more Node.js documentation here and here.
Try Node.js API with DeviceAtlas Enterprise trial
You can apply for a DeviceAtlas Enterprise trial that lets you test the Node.js DeviceAtlas’ API within your specific environment. It allows you to verify if our solution is a good fit for your needs by testing its speed, accuracy, as well as server and memory footprint.
Just click the button, choose Enterprise Trial and fill in the form providing us with some details on your device detection requirements.