Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including nativescript-zxing with all npm packages installed. Try it out:

var nativescriptZxing = require("nativescript-zxing")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

nativescript-zxing v1.5.8

A Simple ZXing barcode reader/writer

npm npm npm

NativeScript ZXing

This is a NativeScript cross platform ZXing library for IOS and Android.


My code is (c)2016-2019, Master Technology. Everything is LICENSED under the APACHE 2.0 License, including libraries, meaning you are free to include this in any type of program -- However for entities that need a support contract, changes, enhancements and/or a commercial license please contact me at

I also do contract work; so if you have a module you want built or sponsored for NativeScript (or any other software projects) feel free to contact me

Donate Patreon


Same plugin works on NativeScript 2.x - 5.x

Run tns plugin add nativescript-zxing in your ROOT directory of your project.


Node: The demo is written to use ImagePicker v6.x; earlier versions will return the results differently and then the demo will fail to run.


Creating a Barcode

var ZXing = require('nativescript-zxing');

var zx = new ZXing();
var img = zx.createBarcode({encode: "Text", height: 100, width: 100, format: ZXing.QR_CODE});

// Do something with the image

This creates a barcode image of 100x100 with the "Text" encoded into the QR Code barcode type. On iOS this will return a UImage which can be assigned to a NativeScript Image; on Android it will return a Bitmap which also can be assigned to a Image. (See Demo)

Decoding a Barcode

var ZXing = require('nativescript-zxing');
var zx = new ZXing();

// Options are TOTALLY optional
var options = {tryHarder: true, formats: [ZXing.QR_CODE, ZXing.ITF]};

var results = zx.decodeBarcode(source, options);
if (!results) {
    console.log("Unable to decode barcode");
} else {
    console.log("Barcode format", results.format);
    console.log("Barcode value", results.barcode);

Please note:

  • The Options are totally optional, if you don't pass in any options it will attempt to decode all known barcode formats. If you do pass in the valid formats; the iOS side actually will ONLY use the formats specified; the Android side will still do some auto-detection.
  • The tryHarder option will cause the decoding to use a more CPU intensive routine; which might find more barcodes.
  • The formats; is just a simple array of any of the supported barcode types listed below.

The source image for Android must be a bitmap; the source image for iOS must be a CGImage. (See Demo)


Please see the demo source for how to read, write and convert between image formats. In addition when you SAVE on Android it might take a few minutes before the media indexer will actually see the new image to put it in the image picker.

Supported Barcode Types

ZXing supports the following Barcode types:

  • UPC_A
  • UPC_E
  • CODE_39
  • CODE_93
  • CODE_128
  • EAN_8
  • EAN_13
  • ITF
  • PDF_417


If you are using nativescript-barcodescanner these two plugins conflict because they use the same library to do the barcode work. The NativeScript tool unfortunately is not smart enough to detect this, and so you will get a weird error during the build.

The easiest fix if you want to use both of them is to open up where the plugin was installed (node_modules/nativescript-zxing) and then delete the platforms/android folder inside my plugin.

My code will then automatically use the version of zxing that nativescript-barcodescanner has included in it.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free