Automatic updates example for 51Degrees device detection ‘Hash’ engine
shows how to build a pipeline using the 51Degrees device detection pipeline builder
and demonstrates how to configure the update polling interval.
The automatic data file updates
page explains the different options you can configure.
This example requires a local data file. The free 'Lite' data file can be acquired by
pulling the git submodules under this repository (run `git submodule update --recursive`)
or from the device-detection-data
GitHub repository.
The Lite data file is only used for illustration, and has limited accuracy and capabilities.
Find out about the more capable data files that are available on our
pricing page
This example requires a subscription to 51Degrees Device Data, a subscription can be acquired
from the 51Degrees pricing page.
const path = require('path');
require((process.env.directory || __dirname) +
'/../../../deviceDetectionOnPremisePipelineBuilder');
const LITE_V_4_1_HASH = '51Degrees-LiteV4.1.hash';
const args = process.argv.slice(2);
const datafile = args.length > 0 ? args[0] :
ExampleUtils.
findFile(LITE_V_4_1_HASH);
const myLicenseKey = process.env.LICENSE_KEY || '!!YOUR_LICENSE_KEY!!';
if (myLicenseKey === '!!YOUR_LICENSE_KEY!!') {
console.log("You need a license key to run this example, if you don't have one already " +
'you can obtain one by subscribing to a 51Degrees bundle: https://51degrees.com/pricing');
} else {
const fs = require('fs');
if (!fs.existsSync(datafile)) {
console.error('Failed to find a device detection ' +
'data file. Make sure the device-detection-data ' +
'submodule has been updated by running ' +
'`git submodule update --recursive`.');
throw ("No data file at '" + datafile + "'");
}
dataFile: datafile,
licenceKeys: myLicenseKey,
autoUpdate: true,
pollingInterval: 1,
updateTimeMaximumRandomisation: 10
}).build();
pipeline.on('error', console.error);
}