generate barcode in node.js

Barcodes visually represent data as graphic symbols. Different types, such as Code128, QR code, Aztec, and PDF417, serve various purposes. In this article you will learn how to add barcode generation to your web applications, including how to generate barcodes of different symbologies within Node.js applications.

Node.js Barcode Generator API

To generate barcodes we use Aspose.BarCode for Node.js via Java. This feature‑rich API lets you create and read popular barcode symbologies from Node.js. Download the API or install it with NPM:

> npm install aspose.barcode

Aspose.BarCode for Node.js via Java supports many barcode symbologies.

Australia PostEAN8
AztecInterleaved2of5
BarCode supplementITF14
BooklandEANMatrix 2 of 5
CodabarMSI
Code11Pdf417
Code128Planet
Code39 ExtendedPostnet
Code39 StandardPZN (Pharma Zentral Nummer, Pharmazentralnummer barcode)
Code93 ExtendedQR
Code93 StandardSSCC18
DatamatrixStandard2of5
Deutsche Post IdentcodeSwiss QR
EAN128UPCA
EAN13UPCE
EAN14(SCC14)

Generate a Barcode in Node.js

Follow these steps to create a barcode in Node.js:

  • Create a BarcodeGenerator object and set the type, e.g., EncodeTypes.CODE_128.
  • Set the barcode text with BarcodeGenerator.setCodeText(string).
  • Save the image using BarcodeGenerator.save(string, string).

The sample below generates a barcode image.

Barcode

generate barcode node.js

Generate a QR Code in Node.js

Aspose.BarCode also creates two‑dimensional barcodes such as QR codes. Use these steps:

  • Instantiate BarcodeGenerator with EncodeTypes.QR.
  • Set the QR text via BarcodeGenerator.setCodeText(string).
  • Save the QR image with BarcodeGenerator.save(string, string).

The code sample below shows QR code generation.

QR Code

generate QR node.js

Customize Appearance of a Barcode

You can change a barcode’s forecolor, back color, font, border, resolution, and more. Steps:

  • Create a BarcodeGenerator object with the desired type, e.g., EncodeTypes.AZTEC.
  • Set the text using BarcodeGenerator.setCodeText(string).
  • Adjust appearance via parameters, such as BarcodeGenerator.getParameters().setBackColor("#A9A9A9").
  • Save the customized image with BarcodeGenerator.save(string, string).

The example below customizes a barcode.

Barcode

customize barcode

Get a Free API License

To remove evaluation limits, you can get a free temporary license.

Conclusion

You have learned how to generate barcodes and QR codes in Node.js and how to customize their appearance. Explore more features in the API’s documentation and share questions on our forum.

See Also