How to generate a UPC-A barcode as a PNG file in Node.JS

Setting up a barcode generating function can be a bit challenging. That’s why we took the liberty of doing it for you from start to finish. We’ve packaged up the result in an API that can be accessed with a simple function call. Prepare to save a ton of time on generating UPC-A format barcodes.

Install our API first. Simply add this reference to your package.json.

"dependencies": {
"cloudmersive-barcodeapi-client": "^1.1.2"

Now call generateBarcodeUPCA:

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.GenerateBarcodeApi();var value = "value_example"; // String | UPC-A barcode value to generate fromvar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.generateBarcodeUPCA(value, callback);

That’s it! Any string value entered will be converted into barcode format and sent back by the API as a PNG file. Simple as that.

Image for post

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