Skip to main content

Node.js quick start for the Linux Barcode Scanner SDK

Build a lightweight barcode scanner in Node.js for Linux.

Create the project and install the Scanbot SDK

1. Create a new project

mkdir barcode-quickstart-node && cd barcode-quickstart-node
npm init -y

2. Install the Scanbot SDK

Replace <SCANBOT_SDK_VERSION> with the version number you want to install.

export SCANBOT_SDK_VERSION=<SCANBOT_SDK_VERSION>
npm install https://github.com/doo/scanbot-sdk-example-linux/releases/download/standalone-sdk%2Fv${SCANBOT_SDK_VERSION}/nodejs-scanbotsdk-${SCANBOT_SDK_VERSION}.tgz

3. Verify the installation

Run a quick sanity check:

node -e "console.log(require('scanbotsdk') ? 'Scanbot SDK loaded' : 'Error')"

Project layout

Create a minimal project folder with a single entry-point.

touch main.ts

Initialize the Scanbot SDK

Before using any feature initialize the SDK.

import * as ScanbotSDK from "scanbotsdk";

const SCANBOT_LICENSE_KEY = "<SCANBOTSDK-LICENSE-KEY>";

async function initializeSdk(): Promise<void> {
await ScanbotSDK.initialize({ licenseKey: SCANBOT_LICENSE_KEY });
const info = ScanbotSDK.getLicenseInfo();
const licenseInfo = await ScanbotSDK.getLicenseInfo();
console.log("License Status:", licenseInfo.status);
}

async function main(): Promise<void> {
await initializeSdk();
}

void main();

Create and run the Barcode Scanner

After successful initialization, create a scanner configuration and run it on an ImageRef.

async function runBarcodeScanner(image: ScanbotSDK.ImageRef): Promise<void> {
const config = new ScanbotSDK.BarcodeScannerConfiguration();
// Configure other parameters as needed.

await using scanner = await ScanbotSDK.BarcodeScanner.create(config);
await using result = await scanner.run(image);

if (result.barcodes.length === 0) {
console.log("No barcodes found.");
return;
}

result.barcodes.forEach((b, i) => {
console.log(`Barcode #${i + 1}:`);
console.log(` Format: ${b.format}`);
console.log(` Text: ${b.text}`);
});
}

Complete example

import * as ScanbotSDK from "scanbotsdk";

const SCANBOT_LICENSE_KEY = "<SCANBOTSDK-LICENSE-KEY>";

async function initializeSdk(): Promise<void> {
await ScanbotSDK.initialize({ licenseKey: SCANBOT_LICENSE_KEY });
const info = ScanbotSDK.getLicenseInfo();
const licenseInfo = await ScanbotSDK.getLicenseInfo();
console.log("License Status:", licenseInfo.status);
}

async function main(): Promise<void> {
const [imagePath] = process.argv.slice(2);
if (!imagePath) {
console.error("Usage: npx ts-node main.ts /path/to/image_with_barcodes.jpg");
}

await initializeSdk();
await using image = await ScanbotSDK.ImageRef.fromPath(imagePath);
await runBarcodeScanner(image);
}

async function runBarcodeScanner(image: ScanbotSDK.ImageRef): Promise<void> {
const config = new ScanbotSDK.BarcodeScannerConfiguration();
// Configure other parameters as needed.

await using scanner = await ScanbotSDK.BarcodeScanner.create(config);
await using result = await scanner.run(image);

if (result.barcodes.length === 0) {
console.log("No barcodes found.");
return;
}

result.barcodes.forEach((b, i) => {
console.log(`Barcode #${i + 1}:`);
console.log(` Format: ${b.format}`);
console.log(` Text: ${b.text}`);
});
}

void main();

Run

npx ts-node main.ts /path/to/image.jpg

🚀 That's it! You've built a minimal barcode scanner in Node.js on Linux.

💡 In this quick start guide, we use the SDK's default scanner settings. However, you can freely customize the configuration, supported barcode types, and performance options.

Get in touch

If you need further information or are interested in licensing the Scanbot SDK, please get in touch with our solution experts.