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

Working with UPC-E barcodes in Node.JS is nobody’s idea of an entertaining afternoon. So why put up with it? Why not use an API instead that will do it for you? Well, that’s exactly what I’m going to demonstrate for you right now. Let’s dive in.

To install, add this dependency reference into your package.json file:

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

Once installation has finished, it’s now time to call our function for UPC-E:

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-E 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.generateBarcodeUPCE(value, callback);

Any string that is entered in for the value will be packaged up nicely as a barcode and sent back to you in PNG form. Super easy. We have a whole lot of other useful barcode APIs that cover a variety of formats, including UPC-A and QR.

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