This article guides on how to scan barcode with Node.js REST API. You will learn to develop a barcode analyzer with Node.js RESTful Service using a Node.js-based Cloud SDK. It will provide an explanation to access and display different properties of a barcode from an image in various formats such as JPEG, TIFF, PNG, BMP, and GIF.
Prerequisite
- Create an account and get API credentials for reading a barcode
- Download Aspose.BarCode Cloud SDK for Node.js to read multiple barcodes from an image
- Set up a Node.js project with the above SDK
Steps to Read Barcode with Node.js .Node.js-based API
- Add the required namespace Aspose.BarCode.Cloud.Sdk.Api to access the Barcode Cloud API classes
- Create a Configuration object and set the API base URL, ClientId, and ClientSecret for authentication
- Define the file name and open it using a FileStream to provide input for scanning
- Create an instance of the ScanApi class using the configuration to interact with the barcode scanning service
- Call ScanMultipartAsync(fileStream) to process the input image and retrieve recognized barcode details
- Loop through the result.Barcodes collection to access each recognized barcode
- Print out the file name, barcode value, and barcode type for each detected barcode
These steps summarize how to read barcode with Node.js Low Code API. First, you connect to Aspose Barcode Cloud by setting up your credentials and loading the barcode image you want to scan. Then, the code uses the Scan API to read the image and prints out the barcode value and the type it finds.
Code to Read Barcode from Image with Node.js REST API
The above code demonstrates the working of a barcode scanner app with Node.js REST API. From the BarcodeResponse object, you can get details like the barcode’s actual value, its type, the region where it was found, and even its checksum. In simple terms, it gives you both the content of the barcode and useful extra info about how and where it was detected.
This article has taught us the process to read a barcode from an image. To generate a barcode, refer to the article on Generate Barcode with Node.js REST API.