Barcodes have become an essential part of the purchase process of the products. In a barcode, the information is represented as a one or two-dimensional graphical object. These graphical objects are recognized to read the encoded information. In order to automate barcode recognition, this article covers how to read barcodes in Node.js using barcode reader API.
- Node.js Barcode Reader API
- Read Barcodes in Node.js
- Read a Specific Barcode Type from an Image
- Switch Barcode Recognition Modes
Node.js Barcode Reader API
In order to read the barcodes from within the Node.js applications, we’ll use Aspose.BarCode for Node.js via Java. It is a feature-rich API that lets you generate, scan, and read a wide range of barcode symbologies. You can either download the API’s package or install it using the following NPM command.
> npm install aspose.barcode
Read Barcodes in Node.js
The following are the steps to read barcodes from an image in Node.js.
- Create an object of BarCodeReader class and initialize it with the barcode image file.
- Use BarCodeReader.readBarCodes() method to read the barcodes’ text and type name.
The following code sample shows how to read barcodes in Node.js.
Read a Specific Barcode Type in Node.js
You can also specify the type of barcode you want to read from the given image. As an example, the following are the steps to read a Code128 barcode.
- First, create an object of BarCodeReader class and initialize it with the barcode image and type.
- Use BarCodeReader.readBarCodes() method to read the barcodes’ text and type name.
The following code sample shows how to read a specific barcode in Node.js.
Switch Barcode Recognition Modes
You can also switch the barcode recognition modes in order to tune the processing speed and quality as required. The following quality settings are supported by the API at the moment.
- Hight Performance: To recognize high-quality barcodes.
- Hight Quality: For low-quality barcodes.
- Max Barcodes: To recognize all possible barcodes, even incorrect barcodes.
- Normal Quality: Suitable for most of the barcodes.
The following are the steps to specify quality settings in barcode recognition process.
- First, load the barcode image using BarCodeReader class and specify the type of barcode.
- Set barcode recognition settings using BarCodeReader.setQualitySettings() method.
- Finally, use BarCodeReader.readBarCodes() method to read the barcodes’ text and type name.
The following code sample shows how to specify quality settings in barcode recognition in Node.js.
Get a Free API License
In order to use the API without evaluation limitations, you can get a free temporary license.
Conclusion
In this article, you have learned how to read barcodes in Node.js applications using barcode reader API. Furthermore, you have seen how to read barcodes with different quality settings. You can explore more about the API using its documentation and code samples available in the downloadable package. In addition, you can share your queries with us via our forum.