How to Scan a Barcode Image and Extract the Data in Node.JS

Barcodes are an important part of many businesses, and integrating barcode functionality into your app or website can be crucial. With that in mind, today I’m going to demonstrate a very easy method that will allow you to convert an image of almost any barcode into its contained data as a string. It’s so easy that I’m only going to need about 5 minutes of your time. How about we get started.

First we must install our API client with this npm install command:

npm install cloudmersive-barcodeapi-client --save

Next call barcodeScanImage.

var CloudmersiveBarcodeapiClient = require('cloudmersive-barcodeapi-client');var defaultClient = CloudmersiveBarcodeapiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveBarcodeapiClient.BarcodeScanApi();var imageFile = "/path/to/file"; // 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);

And you are all ready to go! Now any barcode image that you input will be decoded by the API and sent back in string form. Easy. This API supports the following formats: CODABAR, CODE-39, CODE-93, CODE-128, AZTEC, EAN-8, EAN-13, DATA-MATRIX, ITF, MAXICODE, PDF-417, QR-CODE, RSS14, RSS-EPANDED, UPC-A, UPC-E, ALL-1D, UPC-EAN-EXTENSION, MSI, PLESSEY, and IMB.

Image for post
Image for post

Written by

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

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