npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dynamsoft-node-barcode

v8.8.7

Published

Dynamsoft Barcode Reader Node is a recognition SDK which enables you to embed barcode reading functionality in your applications. With a few lines of JavaScript code, you can develop a robust application to scan a linear barcode, QR Code, DaraMatrix, PDF4

Downloads

58

Readme

Dynamsoft JavaScript Barcode SDK for Node

This library is the Node.js edition of Dynamsoft Barcode Reader. If you are looking to implement barcode reading feature in a web page, please check out the other library Dynamsoft JavaScript Barcode SDK for Web.

Both 1D and 2D barcode symbologies are supported including the popular Code 39, EAN-13, QR, PDF417, etc. Find the full list here.

The library is based on webassembly which has been an official feature of Node.js since LTS 8. If you are using Node.js LTS 8 and have no plan to upgrade it, check out how to use the library in Node.js LTS 8. That said, Node.js version >= LTS 12 is recommended because the library will try to use worker_threads when decoding.

Node.js 15+ is required when using an online license.

Technical Support

Note that the node.js edition of the Barcode Reader may not be updated in time. If you need technical support, you can contact Dynamsoft support or create issues in https://github.com/Dynamsoft/javascript-barcode.

Get Started

  • Check your Node.js version
> node -v
v12.13.1
  • Installs the library from npm
> npm install dynamsoft-node-barcode --save
  • Create a js file and include the library
let DBR = require("dynamsoft-node-barcode");

The following also works

let DBR = require("path/to/dist/dbr.js");

Note The library uses Promise a lot, so it's recommended to write the related code in a async function so that later you can use await

(async()=>{
// many work will done here
})();
  • Create an instance of the reader
let reader = await DBR.BarcodeReader.createInstance();
  • Decode a file by its path
let results = await reader.decode('path/to/sample.png');

Or just decode a file by its URL

let results = await reader.decode('https://demo.dynamsoft.com/barcode-reader/img/AllSupportedBarcodeTypes.png');

NOTE
The following image formats are supported by default: png, jpg, bmp, gif.

If you want to decode other files like pdf's, you need to convert them to images first. Contact Dynamsoft Support to find out more.

If you want to decode raw image data (RGBA) from sources like a camera. You can use the API deocdeBuffer. Check out C++ API decodeBuffer for more details.

  • Print out the results
for(let result of results){
    console.log(result.barcodeText);
}
  • Run your code.
> node your-code.js

Last not but least, don't forget to set a license key! If you don't have a key yet, click here to get one.

DBR.BarcodeReader.license = 'LICENSE';

Full code

let DBR = require('dynamsoft-node-barcode');
// Please visit https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&package=js&utm_source=node to get a trial license
DBR.BarcodeReader.license = 'LICENSE';

let pReader = null;
(async()=>{
    let reader = await DBR.BarcodeReader.createInstance();
    for(let result of await reader.decode('https://demo.dynamsoft.com/barcode-reader/img/AllSupportedBarcodeTypes.png')){
        console.log(result.barcodeText);
    }
    reader.destroy();
    
    // Since the worker keep alive, you can call
    await DBR.BarcodeReader._dbrWorker.terminate();
    // when you need to exit this process.
    // Or call
    process.exit();
    // directly.
})();

Decode from more image sources

let DBR = require('dynamsoft-node-barcode');
// Please visit https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&package=js&utm_source=node to get a trial license
DBR.BarcodeReader.license = 'LICENSE';

(async()=>{
    console.log("============== create reader ==============");
    let reader = await BarcodeReader.createInstance();
    console.log("============== decode buffer ==============");
    let fs = require('fs');
    let buffer = fs.readFileSync(__dirname + '/sample.png');
    for(let result of await reader.decode(buffer)){
        console.log(result.barcodeText);
    }
    console.log("============== decode base64 ==============");
    let strBase64 = buffer.toString('base64');
    for(let result of await reader.decodeBase64String(strBase64)){
        console.log(result.barcodeText);
    }
    console.log("============== decode file ==============");
    for(let result of await reader.decode(__dirname + '/sample.png')){
        console.log(result.barcodeText);
    }
    console.log("============== decode url ==============");
    for(let result of await reader.decode('https://demo.dynamsoft.com/barcode-reader/img/AllSupportedBarcodeTypes.png')){
        console.log(result.barcodeText);
    }
    console.log("============== destroy reader ==============");
    await reader.destroy();
    
    // Since the worker keep alive, you can call
    await DBR._dbrWorker.terminate();
    // when you need to exit this process.
    // Or call
    process.exit();
    // directly.
})();

Change Decoding Settings

To set up the library for decoding, use the APIs getRuntimeSettings & updateRuntimeSettings.

await reader.updateRuntimeSettings("speed");
await reader.updateRuntimeSettings("balance");
await reader.updateRuntimeSettings("coverage");
let settings = await reader.getRuntimeSettings();
settings.localizationModes = [
    Dynamsoft.DBR.EnumLocalizationMode.LM_CONNECTED_BLOCKS,
    Dynamsoft.DBR.EnumLocalizationMode.LM_SCAN_DIRECTLY,
    Dynamsoft.DBR.EnumLocalizationMode.LM_LINES, 0, 0, 0, 0, 0];
settings.deblurLevel = 2;
await reader.updateRuntimeSettings(settings);

See Barcode reading settings Guide for basic usage.

See C++ API RuntimeSettings for more details.

To find out which settings best suit your usage scenario, visit DBR Main Online Demo.

Any questions, please contact Dynamsoft support.

How to use the library in Node.js LTS 8

Node.js LTS 8 doesn't support worker_threads, so the decoding will happen in the same main thread which means it's a blocking operation. The following code snippets demonstrate the basic usage.

Decode

var dbr = require('path/to/dist/dbr-<version>.node.wasm.js');
dbr.onRuntimeInitialized = ()=>{
    dbr.BarcodeReaderWasm.init('{"pk":"PRODUCT-KEY"}');
    var reader = new dbr.BarcodeReaderWasm(false,-1);
    var fs = require('fs');
    var img = fs.readFileSync('./sample.png');
    var resultsInfo = JSON.parse(reader.decodeFileInMemory(new Uint8Array(img)));
    console.log(resultsInfo);
};

Change settings

var settings = JSON.parse(reader.getRuntimeSettings());
settings.expectedBarcodesCount = 999;
reader.updateRuntimeSettings(JSON.stringify(settings));