Scan a Barcode Image in Node.JS
In some of our previous articles, we discussed how you can generate barcode images for use on product packaging. The following API will allow you to then scan those images and return the resulting item details. This image scan supports many different barcode types including AZTEC, CODABAR, CODE_39, CODE_93, CODE_128, DATA_MATRIX, EAN_8, EAN_13, ITF, MAXICODE, PDF_417, QR_CODE, RSS_14, RSS_EXPANDED, UPC_A, UPC_E, All_1D, UPC_EAN_EXTENSION, MSI, PLESSEY, IMB.
Run this command to install the SDK:
npm install cloudmersive-barcodeapi-client --save
Or add this snippet to your package.json:
"dependencies": {
"cloudmersive-barcodeapi-client": "^1.1.2"
}
Then, call the function:
var CloudmersiveBarcodeapiClient = require('cloudmersive-barcodeapi-client');
var defaultClient = CloudmersiveBarcodeapiClient.ApiClient.instance;// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';var apiInstance = new CloudmersiveBarcodeapiClient.BarcodeScanApi();var imageFile = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // File | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.barcodeScanImage(imageFile, callback);
This will return whether the scan was successful, the barcode type, and the raw text contained in the code. You can retrieve the API Key from the Cloudmersive website at no cost and with no commitment. This will provide you with 800 monthly calls across our library of APIs.